2
votes

How to put a split bar in between the left node and center node of a BorderPane? The UI should works as below:

1) When the application windows is resized horizontally, the center resizes horizontally. When the windows resized vertically, the center and the left resize vertically. (These are the default behaviors of BordePane).

2) User can drag to move the space/ bar in between the left and center to resize them horizontally.

Can I combine the BorderPane and SplitPane to achieve this? Any idea?

1

1 Answers

4
votes

Set the SplitPane.resizableWithParent property to false for the left item:

@Override
public void start(Stage stage) {
    Region left = new Region();
    left.setStyle("-fx-background-color: red;");
    Region right = new Region();
    right.setStyle("-fx-background-color: blue;");

    // left node shouldn't resize with BorderPane
    SplitPane.setResizableWithParent(left, Boolean.FALSE);

    SplitPane center = new SplitPane(left, right);
    center.setPrefSize(400, 400);

    BorderPane root = new BorderPane(center);

    Scene scene = new Scene(root);
    stage.setScene(scene);
    stage.show();
}