Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reliably get row index in JTable from MouseEvent?

Tags:

java

swing

jtable

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

like image 770
Łukasz Bownik Avatar asked Oct 28 '08 14:10

Łukasz Bownik


2 Answers

Try this:

aJTable.rowAtPoint(evt.getPoint());

like image 118
Paul Tomblin Avatar answered Sep 21 '22 08:09

Paul Tomblin


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();     } }); 
like image 21
oxbow_lakes Avatar answered Sep 21 '22 08:09

oxbow_lakes