Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

When I implement MouseListener and use the event.getX() it's wrong!

843806Jan 22 2009 — edited Jan 23 2009
Hello

I've have this code snippet:
public void mousePressed(MouseEvent e) {
System.out.println("x: " +e.getX()+ ", y: " +e.getY());
}
When I press the mouse in the windows upper left corner the (x,y) should be (0,0) but I get (4,30)?

Have any of you tried this before and how can I fix it?
I have put 2 JLayeredPane's in a JFrame with BorderLayout, when i use the getLocation on the layered panes I get the correct cordinates, but when I'm clicking on the upper left corner with the mouse and write the coordinate to the screen they are not correct. hmm


I later want to use:
Component c =  board.findComponentAt(e.getY(), e.getY());
And then it takes the wrong component.. :/

please help!

Regards
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 20 2009
Added on Jan 22 2009
4 comments
330 views