Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Finding mouse X,Y without a MouseEvent object

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic