Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

(Java) Get Mouse Coordinates Within Window

I wanted to ask if there Is any way to get the Coordinates my coursor has within my window?

like "e.getX()" when using an Event, but without having to use an event?

or is there any sort of algorithm like getting the absolute position of the mouse and subtracting the position of the Frame?

Thanks Already and sorry for my bad english.

like image 681
Topher Avatar asked Mar 26 '26 06:03

Topher


1 Answers

Ok Guys i found the solution now:

 MouseInfo.getPointerInfo().getLocation().x - XYZ.getLocationOnScreen().x
 MouseInfo.getPointerInfo().getLocation().y - XYZ.getLocationOnScreen().y

with XYZ being the reference to the Frame / Panel / whatever being used

like image 158
Topher Avatar answered Mar 28 '26 18:03

Topher



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!