'Java: row's index does not changes when sorted
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()));
Solution 1:[1]
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).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Rob Spoor |
