I have the following Problem.
Let’s Say I have a JTable with the folowing Values:
1
2
3
4
5
Now I select “3” and press a button which saves the index of the row and prints “3”
I have another Button let’s call it the “next button”, when I press it it will print “4”
Now I sort (Or in this Case just randomise) the whole Table and it’s now like this:
2
5
4
1
3
When I now press the “next button” I want it to print “1” because it’s the value after “4”.
How can I manage this to work ?
It already works when I’m not sorting the Table than I can just print the saved row +1…
Is there something like a sort Listener so I can overwrite the saved row with the new value?
Cheers Timothy
I suggest you dive into the world of
TableModel. When programming in Swing it is usually best to split the model from the component straight away. Add a column to the table to handle order, but don’t show it.A simpler method, but a bit of a dead end, is to make the the object stored in the table of a type of your own devising. Just override
toStringto return the display representation.