我正在尝试使用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);
}
此代码可以正常工作。我在所有区域都有一个“边框边框”。
如果需要,我可以调整区域大小并完全隐藏它们。
但是,如果区域内有任何节点,则无法隐藏区域。我只是可以将它们最小化,直到节点被接受为止。这是一个例子。
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。
但是我无法完全隐藏这些区域。
是否可以更改区域的大小,直到它们完全隐藏?
答案 0 :(得分:2)
我找到了解决方案。子节点的minSize设置为0。然后一切正常。
buttonTop.setMinSize(0, 0);
buttonLeft.setMinSize(0, 0);
buttonCenter.setMinSize(0, 0);
buttonRight.setMinSize(0, 0);
buttonBottom.setMinSize(0, 0);