5 Replies Latest reply: Mar 10, 2013 9:38 PM by James_D RSS

    setting divider postion

    Celer
      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
          jsmith
          Please provide an executable example.
          • 2. Re: setting divider postion
            Celer
            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
              shakir.gusaroff
              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 {
               
                  @Override
                  public void start(Stage primaryStage) {
                    final  SplitPane sp = new SplitPane();
                      sp.setStyle(null);
                      final StackPane sp1 = new StackPane();
                      
                      Button btnOne =  new Button("Button One");
                      
                      btnOne.setOnAction(new EventHandler<ActionEvent>() {
                          @Override
                          public void handle(ActionEvent event) {
                             Platform.runLater(new Runnable() {
                                  @Override
                                  public void run() {
                                      sp.setDividerPosition(0, sp.getDividers().get(0).getPosition() + .1 );
                                     
                                  }
                              });
                             
                          }
                      });
                      
                      
                       Button btnTwo =  new Button("Button Two");
                       btnTwo.setOnAction(new EventHandler<ActionEvent>() {
                          @Override
                          public void handle(ActionEvent event) {
                             Platform.runLater(new Runnable() {
                                  @Override
                                  public void run() {
                                                       
                                      sp.setDividerPosition(0,  Double.valueOf( "0.266456456456"));
                                      System.out.println(sp.getDividers().get(0).getPosition());       
                                  }
                              });
                              
                          }
                      });
                      
                      
                      sp1.getChildren().add(btnOne);
                      final StackPane sp2 = new StackPane();
                      sp2.getChildren().add(btnTwo);
                      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!");
                      primaryStage.setScene(scene);
                      primaryStage.show();
                     
                      
                  }
               
                 
                  public static void main(String[] args) {
                      launch(args);
                  }
              }
              
               
              • 4. Re: setting divider postion
                995935
                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
                  James_D
                  Dejay, you may want to check out {thread:id=2503701}