#Pointer position is based on the location of the frame on the monitor?
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.
Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.
This is the code that I am referring to: ```@Override
public void mouseDragged(MouseEvent e) {
mousePosition.setXY((int) e.getXOnScreen(), (int) e.getYOnScreen());
}
@Override
public void mouseMoved(MouseEvent e) {
mousePosition.setXY((int) e.getXOnScreen(), (int) e.getYOnScreen());
}```
Detected code, here are some useful tools:
public void mouseDragged(MouseEvent e) {
mousePosition.setXY((int ) e.getXOnScreen(), (int ) e.getYOnScreen());
}
@Override
public void mouseMoved(MouseEvent e) {
mousePosition.setXY((int ) e.getXOnScreen(), (int ) e.getYOnScreen());
}
instead of getXOnScreen/getYOnScreen
there should be a method like getX
and getY
I tried that aswell but I got the same result
shouldnt be the case
getXOnScreen
gives you the x location on the whole screen
and getX will give you the x of the component I think
Wait sorry, when I use getX and getY the position isn't based on the position of the window anymore but the pointer is still offsetted too much on the Y axis.
I think this is because of the window bar on the top but I'm not sure.
yeah could be
but it seems like you want to replace the pointer when using the mouse over your window right?
I just need to check if the mouse clicks on objects on the screen
I'm not trying to detect the cursor.
you dont need to handle any mouseevent yourself for that
buttons etc got methods to add code that runs when you click on a component etc
I use a Rectangle as a button and I'm trying to check when the mouse is clicked on the rectangle
why though?
why not use button instead of rectangle
I am aware of this but I thought it was a good idea to implement mouse clicks for things that aren't necessarily buttons.
I was just testing it with a rectangle
then you might want to look into this second answer:
https://stackoverflow.com/questions/26340553/how-do-i-know-if-a-mouse-click-is-done-on-a-custom-component-in-a-panel
or just use a Button
its literally created for smth like that