title: Preserve selected model row in sorted JTable across model update
body: <p>I'm having difficulties getting the following code to preserve the logically selected row in the model if the JTable has been sorted.</p>
  
  <p>It works as intended when no sorting is applied.</p>
  
  <pre><code>private void updateAccountTable() {
      accountsTable = guiFrame.getAccountsTable();
  
      // Preserve selected model row
      String accountNumber = "";
      int selectedRow = accountsTable.getSelectedRow();
      if(selectedRow &gt;= 0){
          accountNumber = (String)accountsTable.getValueAt(selectedRow, 0);
      }
  
      // Preserve sort order
            // Keep eclipse happy.  better way??
      List &lt;? extends SortKey&gt; keys = accountsTable.getRowSorter().getSortKeys();
  
      // Update displayed accounts
      DefaultTableModel model = (DefaultTableModel) accountsTable.getModel();
      model.getDataVector().clear();
  
      Object[][] tableContents = accountList.getAccountsAsArray(true);
      model.setDataVector(tableContents, tableHeaders);
      model.fireTableDataChanged();
  
      // reset sort order
      accountsTable.getRowSorter().setSortKeys(keys);
  
      // If updated model contains previously selected account, reselect
      if (!accountNumber.equals("") &amp;&amp; null != accountList.getAccount(accountNumber)){
          for (int row=0; row&lt;accountsTable.getRowCount(); row++){
              String an = (String)accountsTable.getValueAt(row, 0);
              if (an.equalsIgnoreCase(accountNumber)){
                  accountsTable.setRowSelectionInterval(row, row);
                  break;
              }
          }
      }
      else {
          accountsTable.clearSelection();
      }
  }
  </code></pre>
  
  <p>Unfortunately setRowSelectionInterval() doesn't updated the selected row as expected, despite being called with the correct view row number.  It seems to do nothing.</p>
  
  <p>.....So,</p>
  
  <p>Why is setRowSelectionInterval() failing to updated the selection, or what have I missed?</p>