22

How can I find out which row in a JTable the user just clicked?

james.garriss
  • 12,959
  • 7
  • 83
  • 96
Łukasz Bownik
  • 6,149
  • 12
  • 42
  • 60

2 Answers2

34

Try this:

aJTable.rowAtPoint(evt.getPoint());

mtmurdock
  • 12,756
  • 21
  • 65
  • 108
Paul Tomblin
  • 179,021
  • 58
  • 319
  • 408
13

If you only ever care about listening to selections on the JTable:

jTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
    public void valueChanged(ListSelectionEvent e) {
        int sel = jTable.getSelectedRow();
    }
});
oxbow_lakes
  • 133,303
  • 56
  • 317
  • 449