When a user clicks a cell on a JTable
, how do I figure out the row and column of the clicked cell? How would I show this information in a JLabel
?
The existing answer works, but there is an alternate method that may work better if you're not enabling cell selection. Inside your MouseListener
, do something like this:
public void mouseClicked(java.awt.event.MouseEvent event) {
int row = theTable.rowAtPoint(event.getPoint());
int col = theTable.columnAtPoint(event.getPoint());
// ...