加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

文档 – 在JavaFX中获取节点的全局坐标

发布时间:2020-12-14 16:45:21 所属栏目:Java 来源:网络整理
导读:如何获取场景中节点的实际位置.绝对的位置,不管任何容器/转换. 例如,我想要翻译某个节点a,以便它暂时与另一个节点b重叠.所以我希望将其translateX属性设置为b.globalX-a.globalX. 文件说: Defines the X coordinate of the translation that is added to th
如何获取场景中节点的实际位置.绝对的位置,不管任何容器/转换.

例如,我想要翻译某个节点a,以便它暂时与另一个节点b重叠.所以我希望将其translateX属性设置为b.globalX-a.globalX.

文件说:

Defines the X coordinate of the
translation that is added to the
transformed coordinates of this Node
for the purpose of layout. Containers
or Groups performing layout will set
this variable relative to
layoutBounds.minX in order to position
the node at the desired layout
location.

For example,if child should have a
final location of finalX:

child.layoutX = finalX - child.layoutBounds.minX;

也就是说,任何节点的最终坐标应该是

finalX = node.layoutX + node.layoutBounds.minX

但是运行以下代码:

var rect;
Stage {
    title: "Application title"
    width: 250
    height:250
    scene: Scene {
        content: [
            Stack{content:[rect = Rectangle { width:10 height:10}] layoutX:10}
        ]
    }
}

println("finalX = {rect.layoutX+rect.layoutBounds.minX}");

给我finalX = 0.0,而不是finalX = 10.0,因为文档看起来状态.

有没有一个明确的方法来获得JavaFX中绝对最终的定位坐标?

解决方法

对于边界:
bounds = rect.localToScene(rect.getBoundsInLocal());

为JavaFx 1和2工作.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读