Document – get the global coordinates of the node in JavaFX
•
Java
How to get the actual location of nodes in the scene Absolute position, regardless of any container / conversion
For example, I want to translate a node a so that it temporarily overlaps another node B So I want to set its translatex attribute to b.globalx-a.globalx
The document says:
child.layoutX = finalX - child.layoutBounds.minX;
That is, the final coordinates of any node should be
finalX = node.layoutX + node.layoutBounds.minX
However, run the following code:
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}");
Give me finalx = 0.0, not finalx = 10.0, because the document looks like a state
Is there a clear way to get the absolute final positioning coordinates in JavaFX?
Solution
For boundaries:
bounds = rect.localToScene(rect.getBoundsInLocal());
Work for JavaFX 1 and 2
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
