In some situations I need to place a JFrame right where the mouse cursor is located. Do I really need a mouse listener to track mouse move events, or I can just read current mouse position somehow?
Asked
Active
Viewed 1,509 times
8
-
See this: http://stackoverflow.com/questions/2469515/java-mouse-motion-anywhere-on-screen – CloudyMarble Mar 04 '11 at 12:06
-
possible duplicate of [Get Mouse Position](http://stackoverflow.com/questions/1439022/get-mouse-position) – Jason C Mar 23 '14 at 17:18
1 Answers
13
this could help:
MouseInfo.getPointerInfo().getLocation()

oliholz
- 7,447
- 2
- 43
- 82
-
Yes, you can use `myJFrame.setLocation(MouseInfo.getPointerInfo().getLocation());` – olivierlemasle Mar 04 '11 at 11:58