title: JavaFX: Bind to nested position
body: <p>I have a <code>Pane</code> that contains some <code>VBox</code>s and <code>Line</code>s. I want to bind the endpoints of the <code>Line</code>s to the "anchors" inside the <code>VBox</code>s (basically I want to bind to the position of a <code>Node</code> nested arbitrarily deep in the <code>VBox</code>), but I can't figure out what value represents the <code>Node</code>s position relative to the top <code>Pane</code>. I've tried layout properties, translate properties, as well as bounds in local and bounds in parent, and none of them seem to work. What am I missing?</p>
  
  <p>(I can provide a code sample if needed, but I don't think it helps explain my problem any better since I can't get it to work.)</p>
  
  <p>EDIT: I forgot to mention the <code>VBox</code> can be moved around the pane freely, which is why I need to bind the lines.</p>
  
  <p>EDIT: Here's some source showing my progress. I can get the correct location, but it's not binding</p>
  
  <pre><code>public class Graph extends Application {
      private double startX;
      private double startY;
  
      private ObjectBinding&lt;Bounds&gt; bounds;
      private DoubleBinding tx;
      private DoubleBinding ty;
  
      @Override
      public void start(Stage primaryStage) throws Exception {
          Pane pane = new Pane();
          Circle target = new Circle(5, Color.RED);
          VBox node = wrap(target);
          Line connector = new Line();
          bounds = Bindings.createObjectBinding(() -&gt; {
                      Bounds nodeLocal = target.getBoundsInLocal();
                      Bounds nodeScene = target.localToScene(nodeLocal);
                      Bounds nodePane = pane.sceneToLocal(nodeScene);
                      return nodePane;
                  },
                  target.boundsInLocalProperty(),
                  target.localToSceneTransformProperty(),
                  pane.localToSceneTransformProperty()
          );
          connector.setStartX(0);
          connector.setStartY(0);
          tx = Bindings.createDoubleBinding(() -&gt; bounds.get().getMinX(), bounds);
          ty = Bindings.createDoubleBinding(() -&gt; bounds.get().getMinY(), bounds);
          connector.endXProperty().bind(tx);
          connector.endYProperty().bind(ty);
          connector.setStroke(Color.BLACK);
          pane.getChildren().add(node);
          pane.getChildren().add(connector);
          node.relocate(100, 100);
          primaryStage.setScene(new Scene(pane, 300, 300));
          primaryStage.show();
      }
  
      private VBox wrap(Circle target) {
          VBox node = new VBox(new Label("Node"), new StackPane(new Rectangle(50, 50, Color.GRAY), target));
          node.setOnMousePressed(event -&gt; {
              Node source = (Node) event.getSource();
              startX = source.getBoundsInParent().getMinX() - event.getScreenX();
              startY = source.getBoundsInParent().getMinY() - event.getScreenY();
          });
          node.setOnMouseDragged(event -&gt; {
              Node source = (Node) event.getSource();
              double offsetX = event.getScreenX() + startX;
              double offsetY = event.getScreenY() + startY;
              source.relocate(offsetX, offsetY);
          });
          return node;
      }
  }
  </code></pre>