Hello. I am working with graphics in a JFrame. Within a graphics context, I drew a box in the vicinity of 325, 50. I want to check for mouse clicks in this box. I click on the center of the box. I would expect the MouseEvent's getX() and getY() methods to return 325 and 50, but instead they return 329 and 73! It looks like when it comes to getX() and getY() in JFrames, at least, Java adds on the pixels at the left of the JFrame (there are only three or four) and at the top of the JFrame (the ones that make up the title bar). Are there any methods I could call to find out where the mouse is clicked that uses the same coordinate system as, say, drawRect() or drawLine()? Thanks, as always. Art
Joined: Nov 22, 2008
If you nest a JPanel inside your JFrame you will get a more predictable result.
Joined: Nov 08, 2000
You can also find how many pixels it will be out by using Insets, something like this: