• Post Reply Bookmark Topic Watch Topic
  • New Topic

Finding mouse X,Y without a MouseEvent object

 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'd like to find out the X and Y position of the mouse which is over my JTextPane whenever someone presses F7.

At the moment I am storing the last mouse position via a MouseMoved event so that it can be retrieved at a later date when F7 is pressed. However, this must be hopelessly inefficient as this method is being called so very often without need when the mouse is moved on the component.

Does anyone know of some kind of static method or similar that will give me the position? Something like (obviously doesn't exist but):



Cheers, Jared.
 
Craig Wood
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out java.awt.MouseInfo and its companion java.awt.PointerInfo, new in j2se 1.5
 
Jared Cope
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Thanks for replying. My fault, I should have made it clearer that I am still using 1.4 version of Java at the moment.

I think I will have to create my own mouse movement listener and register it somewhere in order to always have the up to date mouse location.

Cheers, Jared.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!