Search code examples
user-interfaceuser-controlsjavafxtooltip

How to display a tooltip according to mouse position? - JavaFX


I have a stackPane, filled with a Circle and a couple of lines.

I want to display a tooltip while hovering over the StackPane and the tooltip should contain the X/Y coords of the mouse.

I know how to get the Coords of the mouse, but I'm unable to find a way of showing the tool tip.

Can any of ou guys help me with that?..


Solution

  • try this...

    Tooltip tp = new Tooltip("at stack tool");
    stackpane.setOnMouseEntered(new EventHandler<MouseEvent>() {
         @Override
         public void handle(MouseEvent t) {
              Node  node =(Node)t.getSource();
              tp.show(node, FxApp.stage.getX()+t.getSceneX(), FxApp.stage.getY()+t.getSceneY());
            }
        });