• Post Reply Bookmark Topic Watch Topic
  • New Topic

JTable cell  RSS feed

 
tadi raja
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I have a JTable with cell data, i want to set the mouse listener to each

cell using hyperlink click.how can i get the mose events from JTable,give

me any sample example ...

Thanks in advance
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not quite sure what you wan to do - each cell should have something in it that looks and acts like a hyperlink?

In that case you could use a custom cell renderer (see here) that acts like a hyperlink; maybe a JLabel that is colored and is underlined. Then you can add a MouseListener to the JLabel that reacts in whichever way you want. The example from the tutorial actually shows a renderer that extends JLabel, so you can use that as the basis for your code.
[ August 17, 2008: Message edited by: Ulf Dittmer ]
 
tadi raja
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i want to get mouse events from JTable cell and pass cell data arguments to another window to show ??
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can add action listeners to table cells in the way I outlined above.

I don't understand what "pass cell data arguments to another window to show" means.
 
Rob Spoor
Sheriff
Posts: 21095
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With the mouse event's point you can get both the row and column of where the user clicked with rowAtPoint and columnAtPoint. You can then use the JTable's getValueAt method to get the data of that cell. Remember to check if either row or column is -1 though.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!