• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JTable... Urgent!

 
Jeff Smith
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I've got a JTable set up to display some data records. I need to be able to get the value at a cell when the user clicks that cell. I can add a MouseListener to the table, but the problem is all it tell's me is that the user clicked somewhere, but has no idea what the row or column of the cell was, how would I go about getting that? Oh, by the way, the table is not editable, and allows only single, non-row, selections.
Thanks,
Jeff
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In your mouse event code put in this:
Point pnt = evt.getPoint();
int row = table.rowAtPoint(pnt);
int col = table.columnAtPoint(pnt);
 
Jeff Smith
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, that's exactly what I needed.
Jeff
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic