5 Replies Latest reply on Mar 11, 2013 2:38 AM by James_D

    setting divider postion

      We are trying set a SplitPane divider location but when calling the set divider using splitPane.setDividerPosition(dividerPos);

      the divider is not resetting its location.
        • 1. Re: setting divider postion
          Please provide an executable example.
          • 2. Re: setting divider postion
            A simple example that we are using is

            String dividerIdAsString = "0.266456456456";
                                     double dividerPos = Double.valueOf(dividerIdAsString);
                                     splitPane.setDividerPosition(0, dividerPos);

            The number we get from called splitPanel.getDividerPosition();
            • 3. Re: setting divider postion
              Hi. It reset the position but not the exact location.
              When I reset it to 0.266456456456 the output shows 0.26706827309236947.

               import javafx.application.Application;
              import javafx.application.Platform;
              import javafx.event.ActionEvent;
              import javafx.event.EventHandler;
              import javafx.scene.Scene;
              import javafx.scene.control.Button;
              import javafx.scene.control.SplitPane;
              import javafx.scene.layout.StackPane;
              import javafx.stage.Stage;
              public class SplitPaneSample1 extends Application {
                  public void start(Stage primaryStage) {
                    final  SplitPane sp = new SplitPane();
                      final StackPane sp1 = new StackPane();
                      Button btnOne =  new Button("Button One");
                      btnOne.setOnAction(new EventHandler<ActionEvent>() {
                          public void handle(ActionEvent event) {
                             Platform.runLater(new Runnable() {
                                  public void run() {
                                      sp.setDividerPosition(0, sp.getDividers().get(0).getPosition() + .1 );
                       Button btnTwo =  new Button("Button Two");
                       btnTwo.setOnAction(new EventHandler<ActionEvent>() {
                          public void handle(ActionEvent event) {
                             Platform.runLater(new Runnable() {
                                  public void run() {
                                      sp.setDividerPosition(0,  Double.valueOf( "0.266456456456"));
                      final StackPane sp2 = new StackPane();
                      final StackPane sp3 = new StackPane();
                      sp.getItems().addAll(sp1, sp2);
                      sp.setDividerPositions(0.3f, 0.6f);
                      Scene scene = new Scene(sp, 500, 450);
                      primaryStage.setTitle("Hello World!");
                  public static void main(String[] args) {
              • 4. Re: setting divider postion
                I have had also problems with setting the SplitPane divider position for a complex application (restoring previous window layout on start of application).
                It seems that you can set the divider position, but afterwards it get's changed during an initial layout path. Things like ScrollPanes with too large children seemed
                to change it.

                My crappy workaround was to create a Transition that just constantly sets the split pane divider for 10 seconds during startup :P
                • 5. Re: setting divider postion
                  Dejay, you may want to check out {thread:id=2503701}