I have a JTable.. When we select one particular row in it and press Enter I want to get hold of the row that has been selected... I added a Key Listener to my table and looking for Enter key.
The moment when the Enter key is pressed and in my listener when I call m_table. getSelectedRow(), it gives me the next row. Like when we select row '1' and press enter, table.getSelectedRow() gives '2'.
In my key Listener i override keyReleased to catch the Enter Event.
This is the default table behavior. If you have observed the row jumping is cyclic. If you hit enter when the last row is selected, it will select the first row.
Now since you know it jumps a row, you can either call the getSelectedRow and subtract 1 from it or, trap the keyPressed event instead of the keyReleased as the keyPressed will give you the correct row selection.
PS. There might be a solution in playing around with key bindings. It is up to you to decide if it is worth the effort. [ August 05, 2008: Message edited by: Maneesh Godbole ]