title: Removing and Adding Rows in a Sorted JTable using AbstractTableModel
body: <p>I have a JTable using AbstractTableModel where I activated the sort with :</p>
  
  <pre><code>table.setAutoCreateRowSorter(true);
  </code></pre>
  
  <p>I have my own insert and delete functions which were working fine as long as the table is not sorted.</p>
  
  <pre><code>private void insertLine(JTable t)
  {
      int posInsert = t.getSelectedRow();
      Group v = new Group("group", "name","val");
      list.add(pos, v);
      GroupTableModel model = (GroupTableModel) t.getModel();
      model.fireTableRowsInserted(posInsert + 1, posInsert + 1);
  }
  
  private void deleteLine(JTable t)
  {
      int posDel = t.getSelectedRow();
      if (posDel != -1)
      {
          list.remove(pos);
          GroupTableModel model = (GroupTableModel) t.getModel();
          model.fireTableRowsDeleted(posDel, posDel);
      }
  }
  </code></pre>
  
  <p>list is an <code>ArrayList&lt;Group&gt;</code> which contain the data displayed in the JTable</p>
  
  <p>When the table is sorted, it delete the wrong lines, and insert in the wrong position (not the selected+1). I tried several combinations using <code>convertRowIndexToModel</code> and <code>convertRowIndexToView</code> without success. The point is to use the right index when deleting from list, and to have a correct display in view side...</p>
  
  <p>EDIT : After debugging, the issue was with the usage of <code>convertRowIndexToView</code>. the selectedRow should be used to fire the change not <code>convertRowIndexToView</code>. Now I have correct content when updating my method like below (same logic for delete) :</p>
  
  <pre><code>private void insertLine(JTable t)
  {
      int posInsert = t.getSelectedRow();
      int modelPosInsert = t.convertRowIndexToModel(posInsert);
      Group v = new Group("group", "name","val");
      list.add(modelPosInsert, v);
      GroupTableModel model = (GroupTableModel) t.getModel();
      model.fireTableRowsInserted(posInsert + 1, posInsert + 1);
  }
  </code></pre>
  
  <p>Now the issue is after the change, the sort is partially lost. Only few lines are changed in random positions ?</p>