使用布局坐标显示工具提示

show tooltip using layout coordinates

基本上我想用屏幕坐标显示 javafx.scene.control.Tooltip

Scene 中,我有几个 Node 实例,每个实例都有自己的 Tooltip 实例。某个事件应该触发所有节点同时显示它们的工具提示。 (这是一种帮助功能)

但是 show 方法使用屏幕坐标。因此,当我使用 tooltip.show(node, node.getLayoutX(), node.getLayoutY()) 时,不幸的是所有工具提示都偏离了几英寸。

如果使用鼠标事件,我会使用 mouseEvent.getScreenX()mouseEvent.getScreenY() 方法来显示工具提示。但不幸的是,这次我没有使用鼠标触发此事件

A Node 没有 getScreenX 方法。那么,有没有办法将布局坐标转换为屏幕坐标?

如果有其他方法,请随时分享。

无法直接从布局坐标转换为屏幕坐标。但是有一个方法localToScreen可以用来将本地坐标转换成屏幕坐标

    Bounds bounds = node.localToScreen(getBoundsInLocal());
    tooltip.show(this, bounds.getMinX(), bounds.getMinY());