• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting mouse events for a component in a Jtable cell  RSS feed

 
Sarone Thach
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
this one is a bit tough I find. What I have is a JTable. It has a CellRenderer which returns a type of JPanel, in the JPanel I have dynamically added JLabels.
I have created a mouseAdapter class and registered mouse listeners for the JLabels. I have code to print out a line of debug if i get a mouseevent.
I want to determine which JLabel the user has clicked.
After some experimenting I find that I cannot get the mouse event for a click on the JLabel, or the JPanel. What it gives me is a JTable mouse event!!
How do I find out which JLabel is clicked if it does not give me a separate event?
Please can someone tell me.
Thanks.
Sarone
 
Terence Doyle
Ranch Hand
Posts: 328
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sarone,
The problem with the JTable/JTree use of renderers is that you 'see' the labels -or whatever you put in there by overriding the getCellRendererComponent() but the objects are not reall there. The table/tree hands over its Graphics object for painting but thats all.
You'll have to detect the x,y of the click to decide which label was clicked.
You could try messing around with the editor components too.
Hope that helps,
Terry Doyle
[ October 30, 2003: Message edited by: Terence Doyle ]
 
Sarone Thach
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Terry, I'm glad you told me that. Now I know for sure what I'm doing is not too much work. I managed to determine which label was clicked or mouse overed, by the Point I recieved from the MouseEvents.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!