• Post Reply Bookmark Topic Watch Topic
  • New Topic

Getting a click's location in relation to a panel  RSS feed

 
James Filson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am currently using the following to get the location of the user's mouse click:

This however gives the location in relation to the whole window. Is there any way of getting the click in relation to the panel that is being clicked? I can't seem to find any reference to this online!

Thank you all in advance.
 
Rob Camick
Ranch Hand
Posts: 2788
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Those method "are relative" to the component that was clicked.

If you added the MouseListener to the panel, then its relative to the panel.

If you added the MouseListener to the frame, then add it to the panel.

If you need to convert Points, then the SwingUtilities class has some methods to do this.

 
James Filson
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks so much! I had no idea you could make a mouse listener relative to an area.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!