Java: row's index does not changes when sorted

109 Views Asked by At

when I sort the row, the indexes of the rows doesn't seems to change at all - thus resulting the old row which was initially in that position before making any sort. here my code is

DefaultTableModel  modelmachine = (DefaultTableModel) jTableMachine2.getModel();
        TableRowSorter<DefaultTableModel> tr = new TableRowSorter<>(modelmachine);
        jTableMachine2.setRowSorter(tr);
        tr.setRowFilter(RowFilter.regexFilter(jTextField8.getText()));
1

There are 1 best solutions below

0
On

Check out RowSorter's convertRowIndexToModel and convertRowIndexToView methods. You're probably getting the model index (the index in the model, which does not have the sorting applied), but you need the view index (the index of what you actually see).