When a user right-clicks you know the position of the right-click (e.getX(), e.getY()). int row = e.getY()/table.rowHeight; The selected row can be found by the above formula. There is also one more way to find the selected row. You can use rowAtPoint() method in JTable to find the selected row. After doing this, you can set the selected row by doing table.setRowSelectionInterval(row,row); Here table is an instance of JTable. Hope it helps. If you have any problems here lemme know. Thanks, - Raja.
Joined: Aug 09, 2001
Hi, can this be done in a JList? Happy middling with java. Netharam.
Joined: May 08, 2002
Even JList has setSelectedIndex() and setSelectionInterval() methods. Refer to API documentation on JList for more explanation. - Raja.