wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes MouseMotionListener question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "MouseMotionListener question" Watch "MouseMotionListener question" New topic

MouseMotionListener question

shawn larkin
Ranch Hand

Joined: Feb 04, 2002
Posts: 34
mouseDragged(MouseEvent event)
int valueX = event.getX();
int valueY = event.getY();
getting the x and the y coordinates of the mouse seem to return a relative number example(-14, 0) instead of an absolute number(546, 873). How could I get that absolute value, and not the relative value based on the component setting the MouseMotionListener. thanks
Rob Ross

Joined: Jan 07, 2002
Posts: 2205
Look up the API documentation for MouseEvent:
getX() : Returns the horizontal x position of the event relative to the source component.
The coordinates are not global to your monitor screen, they are in the coordinates within the component. -14 indicates that the mouse is now 14 pixels to the left of the left side of the component for which the mouseDragged() event was fired.

SCJP 1.4
shawn larkin
Ranch Hand

Joined: Feb 04, 2002
Posts: 34
Hi, thanks for the quick reply. I know about the not global thing, I was just wondering if you knew of a solution.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You'll have to get the Component that launched the event (via event.getSource()), get the screen location of that component(via Component.getScreenLocation()), and add the x and y location of the event to this point.

Voila! You have to x and y location of the event on the screen!


Write once, run anywhere, because there's nowhere to hide! - /. A.C.
shawn larkin
Ranch Hand

Joined: Feb 04, 2002
Posts: 34
thank you very much
I agree. Here's the link: http://aspose.com/file-tools
subject: MouseMotionListener question
Similar Threads
Not able to find a File in servlet
question about Math class
absolute method in mathclass
The problem prototype Ajax.Request
Current value for Resultset..