12

I am trying to find the Starting location/position of the JFrame in order to map the mouse cursor from the JFrame window to desktop. Is there anyway to find the X,Y position of JFrame ?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
nebula
  • 3,932
  • 13
  • 53
  • 82

2 Answers2

28

You can use getLocation() or getLocationOnScreen() method of JFrame which are inherited from java.awt.Component.

Harry Joy
  • 58,650
  • 30
  • 162
  • 207
0

you have to implement the MouseListener Interface and call the override methods

public void mouseEntered(MouseEvent me) 

and use

MouseEvent.getX();

MouseEvent.getXOnScreen();
Madhawa Priyashantha
  • 9,633
  • 7
  • 33
  • 60