如何根据鼠标位置显示工具提示? - JavaFX

如何根据鼠标位置显示工具提示? -  JavaFX

问题描述:

我有一个 stackPane ,里面有一个圆圈和几行。

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

我想要显示将鼠标悬停在StackPane上时工具提示,工具提示应包含鼠标的 X / Y坐标

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

我知道如何获得鼠标的Coords,但我无法找到显示工具提示的方法。

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?..

试试这个...

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());
        }
    });