Preserve JTable selection across TableModel change

前端 未结 7 1617
北荒
北荒 2021-02-07 11:52

We\'re seeing JTable selection get cleared when we do a fireTableDataChanged() or fireTableRowsUpdated() from the TableModel.

7条回答
  •  灰色年华
    2021-02-07 12:25

    for reference, as @Swapnonil Mukherjee stated, this did the trick with a table with selectable rows:

    // preserve selection calling fireTableDataChanged()
    final int[] sel = table.getSelectedRows();
    
    fireTableDataChanged();
    
    for (int i=0; i

提交回复
热议问题