Reputation:
I have the following code:
public class JavaFxApplication2 extends Application {
@Override
public void start(Stage stage) throws Exception {
SplitPane splitPane=new SplitPane();
VBox vBox1=new VBox();
vBox1.setStyle("-fx-background-color: red");
VBox vBox2=new VBox();
vBox2.setStyle("-fx-background-color: blue");
splitPane.getItems().add(vBox1);
splitPane.getItems().add(vBox2);
splitPane.getDividers().get(0).setPosition(0);
Scene scene=new Scene(splitPane, 200, 400);
stage.setScene(scene);
stage.show();
}
}
This is the output when I run application:
Now I resize and make stage larger:
As you see divider position now is not 0. How to disable divider position changing on resizing?
Upvotes: 8
Views: 3338
Reputation: 21799
All the nodes contained by the SplitPane
become resized by default, hence the "wandering divider".
You can use setResizableWithParent
to avoid resizing the left VBox
:
SplitPane.setResizableWithParent(vBox1, false);
Sets a node in the SplitPane to be resizable or not when the SplitPane is resized. By default all node are resizable. Setting value to false will prevent the node from being resized.
If you do not want the right VBox
to be resized, this method has to be called for that node also.
Upvotes: 9