Fetching mouse coordinates

K

Kevin Pors

Is there any way how I can find the coordinates of the mouse on the screen in a static way?
All posts i've read mention the use of MouseListener and other interfaces which needs motion to determine
it. I'd like to find the absolute coordinates where the mouse currently is on the screen - NOT relatively of a
component.
 
K

Kevin Pors

which needs motion to determine
on the screen - NOT relatively of a

Isn't there a getLocationOnScreen method in the Component class?

Well it's more complicated than that. The situation is as follows:

JFrame, grandmother of the application. This frame hold a JToolBar.
On that toolbar I got my own created component, KButton. I want to create my
own style of tooltip which is gonna be visible when I hover over the KButton.

For creating a tooltip thing, I extended JWindow. I need to position that window about 5 pixels down
and 5 pixels to the right of the cursor.

I'd like to get the cursor position of the screen without iterating through all the parents. That
wouldn't be a very clear and vast object oriented manner of programming, IMHO.

Regards,

Kevin
 
T

Tim Tyler

: Is there any way how I can find the coordinates of the mouse on the
: screen in a static way? All posts i've read mention the use of
: MouseListener and other interfaces which needs motion to determine
: it. I'd like to find the absolute coordinates where the mouse currently
: is on the screen - NOT relatively of a component.

Java only lets apps know where the mouse is when it is over a Component.

To read the mouse co-ordinates - and be guaranteed a result - use JNI.
 
T

Tim Tyler

:>Isn't there a getLocationOnScreen method in the Component class?

: Well it's more complicated than that. The situation is as follows:

: JFrame, grandmother of the application. This frame hold a JToolBar.
: On that toolbar I got my own created component, KButton. I want to create my
: own style of tooltip which is gonna be visible when I hover over the KButton.

: For creating a tooltip thing, I extended JWindow. I need to position
: that window about 5 pixels down and 5 pixels to the right of the cursor.

: I'd like to get the cursor position of the screen without iterating
: through all the parents. That wouldn't be a very clear and vast object
: oriented manner of programming, IMHO.

Surely, the "getLocationOnScreen" method does the iteration for you.

There is no cause to be concerned about performance here.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,835
Latest member
KetoRushACVBuy

Latest Threads

Top