title: JavaFX: Button jumps off the binding with SplitPane.Divider
body: <p>I have <code>SplitPane</code> with two <code>AnchorPane</code> (left and right side). There are <code>Label</code>, <code>TextField</code> and <code>Button</code> on each <code>AnchorPane</code>, they are arranged in one line. <code>Label</code> must bind to the left side <code>AnchorPane</code>, <code>Button</code> to the right and <code>TextField</code> must be stretched between them. Left <code>AnchorPane</code> must be bind to left part of <code>SplitPane</code>.</p>
  
  <p>My code works, but when I move divider after some time <code>Buttons</code> jump off the binding with <code>SplitPane</code>.
  <code>AnchorPane</code> width bind to <code>SplitPane.Divider</code>, <code>Label</code>, <code>TextField</code>, <code>Button</code> bind to <code>AnchorPane</code>.
  Can you help me?
  Sorry for my English.</p>
  
  <pre><code>    import javafx.application.Application;
      import javafx.beans.binding.DoubleBinding;
      import javafx.beans.value.ObservableValue;
      import javafx.event.ActionEvent;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.control.Label;
      import javafx.scene.control.SplitPane;
      import javafx.scene.control.TextField;
      import javafx.scene.layout.AnchorPane;
      import javafx.stage.Stage;
  
      public class Main extends Application {
  
          public static void main(String[] args) {
              Application.launch(args);
          }
  
          @Override
          public void start(Stage stage) {
              stage.setTitle("BackUpManager");
              AnchorPane root = new AnchorPane();
              Scene scene = new Scene(root, 800,600);
  
              SplitPane splitPane = new SplitPane();
              splitPane.setLayoutY(50);
              splitPane.prefWidthProperty().bind(root.widthProperty());
              splitPane.prefHeightProperty().bind(root.heightProperty().subtract(50));
  
              AnchorPane rRoot = new AnchorPane();
              AnchorPane wRoot = new AnchorPane();
  
              splitPane.getItems().addAll(rRoot,wRoot);
  
              rRoot.setMinWidth(200);
              rRoot.prefWidthProperty().bind(splitPane.getDividers().get(0).positionProperty());
              Button rBrowse = new Button();
              rRoot.getChildren().add(rBrowse);
              rBrowse.setText("Browse");
              DoubleBinding db0 = rRoot.widthProperty().subtract(55);
              db0.addListener(new javafx.beans.value.ChangeListener&lt;Number&gt;() {
                  public void changed(ObservableValue&lt;? extends Number&gt; ov, Number t, Number t1) {
                      rBrowse.setLayoutX(db0.getValue());
                  }});
              Label rLabel = new Label("Reserve dir");
              rRoot.getChildren().add(rLabel);
              rLabel.setLayoutY(3);
              TextField rPath = new TextField();
              rRoot.getChildren().add(rPath);
              rPath.setLayoutX(60);
              rPath.prefWidthProperty().bind(rRoot.widthProperty().subtract(115));        
  
              wRoot.prefWidthProperty().bind(splitPane.widthProperty().subtract(splitPane.getDividers().get(0).positionProperty()));
              wRoot.setMinWidth(200);
              Button wBrowse = new Button();
              wRoot.getChildren().add(wBrowse);
              wBrowse.setText("Browse");
              DoubleBinding db1 = wRoot.widthProperty().subtract(55);
              db1.addListener(new javafx.beans.value.ChangeListener&lt;Number&gt;() {
                  public void changed(ObservableValue&lt;? extends Number&gt; ov, Number t, Number t1) {
                      wBrowse.setLayoutX(db1.getValue());
                  }});
              Label wLabel = new Label("Working dir");
              wRoot.getChildren().add(wLabel);
              wLabel.setLayoutY(3);
              TextField wPath = new TextField();
              wRoot.getChildren().add(wPath);
              wPath.setLayoutX(64);
              wPath.prefWidthProperty().bind(wRoot.widthProperty().subtract(119));
  
              rBrowse.setOnAction(new EventHandler&lt;ActionEvent&gt;() {
                  @Override
                  public void handle (ActionEvent e) {
                      System.out.println("Called");
                  }
              });
  
              root.getChildren().addAll(splitPane);
              stage.setScene(scene);
              stage.show();
          }
      }
  </code></pre>