如何获取场景中节点的实际位置.绝对的位置,不管任何容器/转换.
例如,我想要翻译某个节点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,因为文档看起来状态.
解决方法
对于边界:
bounds = rect.localToScene(rect.getBoundsInLocal());
为JavaFx 1和2工作.
原文地址:https://www.jb51.cc/java/124466.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。