Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

MouseEvent getY() result is off?  RSS feed

 
Edward Nunez
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys,

The e.getY() method within the mouseMoved(MouseEvent e) method seems to be giving me the wrong value. It's off by 22 points to be exact. I noticed that when I added the mouse listener to my panel rather than my frame (which one of these is better?) the discrepancy doubled to 44 points!

I know that the position is off because I use a robot object to place my mouse to specific location at the end of the mouseMoved method. Anybody have any idea why something like this might happen?
 
Steve Luke
Bartender
Posts: 4181
22
IntelliJ IDE Java Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Compare the coordinate system used by the source of the mouse event and the coordinate system used by the robot. The coordinates used by the event are relative to the top left corner of the component which sent the event. So what coordinate system does the robot use? If you are using Robot#mouseMove() those are in screen coordinates (which means you should be using MouseEvent#getYOnScreen() rather than MouseEvent#getY() I think).
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!