I want to connect two Node
s with a Line
(from center of the first to the center of the second).
Initial thoughts:
- It is assumed that both nodes exist somewhere in the scene graph
- The
Line
acts as a decorator and should not be pickable - If the
Node
Bounds
change, theLine
should be updated
It looks like I will need some compound property bindings including the proper coordinate space transformations.
How to achieve this? Can anyone point out a direction?
The code in this response is based on the answer to the question: CubicCurve JavaFX
The sample below:
The above code is based on a circle, so it is easy to track the circle's centerX and centerY properties.
For an arbitrarily shaped node, you can track it's center properties within it's parent using the code below:
Applying the Center code to the Anchor sample above, you get the following code:
If you wanted to track arbitrary nodes in a scene, not just sibling nodes, you might want to look into the node.getLayoutBounds and node.getLocalToSceneTransform functions.