Since you have not published any of your codes, this may seem obvious, but have you added a mouse event handler to the panel? If so (in my attempt to recreate your problem), the event.getX () and event.getY () methods returned an exepected position.
(did you use getSceneX () and getSceneY ()? in this case change to getX () and getY ())
Another way is to correct the position of the mouse that you get (position on stage) by the position of your panel.
you can do this for the x, y, z axes:
while (node != null){ shift += node.getLayoutY(); node = node.getParent(); }
then subtract this shift to the position of the pointer that you get
Edit:. Looking at your code, it seems that you are adding a MouseEvent handler to the root object. Therefore, the event is fired when the mouse is on the root object. If you add it to your rectangle, for example, the mouse position will be relative to the rectangle.
The following code works for me (but maybe it doesnโt reproduce your problem well).
open class JFXRotationXOrds extends application {
@Override public void start(Stage primaryStage) throws Exception { VBox root = new VBox(); Rectangle rect = new Rectangle(20, 20, Color.BLUE); rect.setOnMouseMoved(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent arg0) { if(arg0.getEventType() == MouseEvent.MOUSE_MOVED){ System.out.println("Rect : " + arg0.getX() + "," + arg0.getY()); } } }); root.getChildren().add(rect); root.getChildren().add(new Circle(20, Color.RED));
source share