Say I have a JTable with some data in it. A call to table.getValueForCell(row,col) returns the contents of the cell. This is as expected.
Now say I want to sort my table. I click the table header (column), and it sorts the table. If I make a call to table.getValueForCell(row,col) with the same values for row and col. There is now a different row here because the table was sorted. However, the table.getValueForCell(row,col) returns the old data. It seems as if the underlying data structures that hold the table data are not updated when sorting.
Any idea on how to fix this, or what I might be doing wrong?
The data is always stored in its original order in the TableModel. You can access the original order using:
table.getModel().getValueAt(...);
Whenever the table is sorted, only the view changes. When you get data from the table you just use:
table.getValueAt(...);
If you some reason you need to convert back and forth between the two you can use either of the approriate table methods:
convertRowIndexToModel(...);
convertRowIndexToView(...);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With