public void reset() { final RowTableModel stm = (RowTableModel) getModel(); final ListSelectionModel lsm = getSelectionModel(); getSelectionModel().clearSelection(); lsm.clearSelection(); stm.reset(); }
/** * load the selections * * @param aTable JTable * @param objs List */ private void loadSelection(JTable aTable, List objs) { final ListSelectionModel lsm = aTable.getSelectionModel(); final RowTableModel tm = (RowTableModel) aTable.getModel(); // reset the selection for (int i = 0; i < objs.size(); i++) { Object obj = objs.get(i); int where = tm.getRow(obj); if (where != -1) { lsm.addSelectionInterval(where, where); } } scrollToVisible(aTable); }
/** * Save the selection so it can be restored after sorting. * * @param aTable * @return List */ private List saveSelection(JTable aTable) { final ListSelectionModel lsm = aTable.getSelectionModel(); final RowTableModel tm = (RowTableModel) aTable.getModel(); final int first = lsm.getMinSelectionIndex(); final int last = lsm.getMaxSelectionIndex(); final List objs = new ArrayList(); if (first != -1) { for (int i = first; i <= last; i++) { if (lsm.isSelectedIndex(i)) { objs.add(tm.getRow(i)); } } } return objs; }