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?
In Mouse Properties, on the Pointer Options tab, at the bottom, select Show location of pointer when I press the CTRL key, and then select OK. To see it in action, press CTRL.
getLocation() might be helpful. It returns a Point object corresponding to current mouse position. getPointerInfo(). getLocation() returns the position relative to the screen.
Mouse move events will occur only when a mouse button is pressed down, unless mouse tracking has been enabled with QWidget::setMouseTracking(). Qt automatically grabs the mouse when a mouse button is pressed inside a widget; the widget will continue to receive mouse events until the last mouse button is released.
this could help:
MouseInfo.getPointerInfo().getLocation()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With