How to reliably get row index in JTable from MouseEvent?
Question
How can I find out which row in a JTable the user just clicked?
Solution
Try this:
aJTable.rowAtPoint(evt.getPoint());
OTHER TIPS
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();
}
});
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow