tags:

views:

13

answers:

2

Hey there,

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

A: 

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 toString to return the display representation.

Tom Hawtin - tackline
yeah of course I use a TableModel. This could actually work that I would have another colum with the ID's. I'll try it out . Thanks for the answer
Timothy
A: 

As i understand that the problem is with the last index , in ur problem that when it's 4 the next one should be 1 . this problem can be done by makeing if condition . fore example if i suppose u save the index in a varible rowIndex = 4; if(rowIndex ==jTable.getRowCount()-1) nextRowinsex = 1 ; // which is the first index

Alaa