我正在尝试使用 SplitPanes 构建一个 BorderPane,以通过拖动鼠标来获得一个具有可调整大小区域的 BorderPane。我写了一些有效的代码。但是如果里面有任何节点,我不能隐藏 SplitPanes 的区域。
首先,我已经建立了这个阶段并且它有效。
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);
}
这段代码工作正常。我有一个包含所有区域的“BorderPane”。
如果我愿意,我可以调整我想要的区域大小并完全隐藏它们。
但如果区域内有任何节点,我无法隐藏这些区域。我可以将它们最小化,直到节点被接受。这是一个例子。
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);
}
}
我有一个 BorderPane。
但我不能完全隐藏这些区域。
是否可以更改区域的大小直到它们完全隐藏?