Reputation: 316
I am trying to build an BorderPane with SplitPanes to get a BorderPane which has resizeable areas by dragging the mouse. I have write some code which is working. But i cant hide the areas of the SplitPanes if there any nodes inside.
First of all i have build this stage and it works.
public class Example extends Application {
StackPane gui;
SplitPane splitVertical;
SplitPane splitHorizontal;
StackPane top;
StackPane left;
StackPane center;
StackPane right;
StackPane bottom;
@Override
public void start(Stage stage) throws Exception {
splitVertical = new SplitPane();
splitVertical.setOrientation(Orientation.VERTICAL);
splitVertical.setDividerPosition(0, 0.25);
splitVertical.setDividerPosition(1, 0.75);
splitVertical.setDividerPosition(2, 1.00);
splitHorizontal = new SplitPane();
splitHorizontal.setOrientation(Orientation.HORIZONTAL);
splitHorizontal.setDividerPosition(0, 0.25);
splitHorizontal.setDividerPosition(1, 0.75);
splitHorizontal.setDividerPosition(2, 1.00);
top = new StackPane();
left = new StackPane();
center = new StackPane();
right = new StackPane();
bottom = new StackPane();
splitVertical.getItems().add(top);
splitVertical.getItems().add(splitHorizontal);
splitHorizontal.getItems().add(left);
splitHorizontal.getItems().add(center);
splitHorizontal.getItems().add(right);
splitVertical.getItems().add(bottom);
gui = new StackPane(splitVertical);
Scene scene = new Scene(gui, 400, 300);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
This code works fine. I have a "BorderPane" with all areas.
And i can resize the areas like i want and hide them completely, if i want.
But if there any nodes inside the areas, i cant hide the areas. I just can minimize them until the node is accepts. Here is an example.
public class Example extends Application {
StackPane gui;
SplitPane splitVertical;
SplitPane splitHorizontal;
StackPane top;
StackPane left;
StackPane center;
StackPane right;
StackPane bottom;
Button buttonTop;
Button buttonLeft;
Button buttonCenter;
Button buttonRight;
Button buttonBottom;
@Override
public void start(Stage stage) throws Exception {
splitVertical = new SplitPane();
splitVertical.setOrientation(Orientation.VERTICAL);
splitVertical.setDividerPosition(0, 0.25);
splitVertical.setDividerPosition(1, 0.75);
splitVertical.setDividerPosition(2, 1.00);
splitHorizontal = new SplitPane();
splitHorizontal.setOrientation(Orientation.HORIZONTAL);
splitHorizontal.setDividerPosition(0, 0.25);
splitHorizontal.setDividerPosition(1, 0.75);
splitHorizontal.setDividerPosition(2, 1.00);
buttonTop = new Button("Top");
buttonLeft = new Button("Left");
buttonCenter = new Button("Center");
buttonRight = new Button("Right");
buttonBottom = new Button("Bottom");
top = new StackPane(buttonTop);
left = new StackPane(buttonLeft);
center = new StackPane(buttonCenter);
right = new StackPane(buttonRight);
bottom = new StackPane(buttonBottom);
splitVertical.getItems().add(top);
splitVertical.getItems().add(splitHorizontal);
splitHorizontal.getItems().add(left);
splitHorizontal.getItems().add(center);
splitHorizontal.getItems().add(right);
splitVertical.getItems().add(bottom);
gui = new StackPane(splitVertical);
Scene scene = new Scene(gui, 400, 300);
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
I got a BorderPane.
But i cant hide the areas completely.
Is it possible to change the size of the areas until they are completely hide?
Upvotes: 2
Views: 165
Reputation: 316
I have found the solution. The minSize of the childnode has set to 0. Then everything works fine.
buttonTop.setMinSize(0, 0);
buttonLeft.setMinSize(0, 0);
buttonCenter.setMinSize(0, 0);
buttonRight.setMinSize(0, 0);
buttonBottom.setMinSize(0, 0);
Upvotes: 2