So I get the mouse position relative to the screen, not the window:

static int mousex; static int mousey; public void mouse(){ this.mousex=(int)MouseInfo.getPointerInfo().getLocation().getX(); this.mousey=(int)MouseInfo.getPointerInfo().getLocation().getY(); } 

How to get the coordinates specifically for the window?

  • Take the coordinates of your window and subtract these values ​​from the absolute coordinates - Andrew Bystrov
  • SwingUtilities.convertPointFromScreen(MouseInfo.getPointerIn‌​fo().getLocation(), component) - Senior Pomidor
  • another solution is stackoverflow.com/a/29187822/6300555 - Senior Pomidor

1 answer 1

You can try to do the same, as advised me: The coordinates of the mouse near the pointer (arrow) in Java .

You create a label on the panel or on the window and, when the mouse pointer moves, change its coordinates while displaying them on it.