0

是否可以使 BorderPane 的右侧具有窗口高度和底部/顶部,然后以右侧的开头结束?

4

2 回答 2

3

AFAIK there is no way to do this, but you can achieve the desired result using a GridPane

private static void setBackground(Region region, Color color) {
    region.setBackground(new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY)));
}

@Override
public void start(Stage primaryStage) {
    GridPane gridPane = new GridPane();
    RowConstraints rConstranits1 = new RowConstraints();
    rConstranits1.setVgrow(Priority.NEVER);
    RowConstraints rConstranits2 = new RowConstraints();
    rConstranits2.setVgrow(Priority.ALWAYS);
    RowConstraints rConstranits3 = new RowConstraints();
    rConstranits3.setVgrow(Priority.NEVER);

    ColumnConstraints cConstraints1 = new ColumnConstraints();
    cConstraints1.setHgrow(Priority.NEVER);
    ColumnConstraints cConstraints2 = new ColumnConstraints();
    cConstraints2.setHgrow(Priority.ALWAYS);
    ColumnConstraints cConstraints3 = new ColumnConstraints();
    cConstraints3.setHgrow(Priority.NEVER);

    gridPane.getColumnConstraints().addAll(cConstraints1, cConstraints2, cConstraints3);
    gridPane.getRowConstraints().addAll(rConstranits1, rConstranits2, rConstranits3);

    Region top = new Region();
    top.setPrefSize(300, 100);
    setBackground(top, Color.RED);

    Region bottom = new Region();
    bottom.setPrefSize(400, 50);
    setBackground(bottom, Color.YELLOW);

    Region center = new Region();
    setBackground(center, Color.BLUE);

    Region right = new Region();
    setBackground(right, Color.LIME);
    right.setPrefSize(200, 500);

    Region left = new Region();
    setBackground(left, Color.BROWN);
    left.setPrefSize(200, 400);

    gridPane.add(right, 2, 0, 1, 3);
    cConstraints3.maxWidthProperty().bind(right.prefWidthProperty());
    cConstraints3.minWidthProperty().bind(right.prefWidthProperty());
    gridPane.add(top, 0, 0, 2, 1);
    rConstranits1.minHeightProperty().bind(top.prefHeightProperty());
    rConstranits1.maxHeightProperty().bind(top.prefHeightProperty());
    gridPane.add(bottom, 0, 2, 2, 1);
    rConstranits3.minHeightProperty().bind(bottom.prefHeightProperty());
    rConstranits3.maxHeightProperty().bind(bottom.prefHeightProperty());
    gridPane.add(center, 1, 1);
    gridPane.add(left, 0, 1);
    cConstraints1.minWidthProperty().bind(left.prefWidthProperty());
    cConstraints1.maxWidthProperty().bind(left.prefWidthProperty());

    Scene scene = new Scene(gridPane);

    primaryStage.setScene(scene);
    primaryStage.show();
}
于 2016-12-11T13:26:42.240 回答
1

嵌套两个 BorderPane 是另一种选择,它依赖于 BorderPane 的内置高度和宽度管理。感谢 fabian 的示例基础和 setBackground 例程!

private static void setBackground(Region region, Color color) {
    region.setBackground(new Background(new BackgroundFill(color, CornerRadii.EMPTY, Insets.EMPTY)));
}

@Override
public void start(Stage primaryStage) {

    BorderPane outer = new BorderPane();
    BorderPane inner = new BorderPane();

    Region top = new Region();
    top.setPrefSize(300, 300);
    setBackground(top, Color.RED);

    Region bottom = new Region();
    bottom.setPrefSize(400, 200);
    setBackground(bottom, Color.YELLOW);

    Region right = new Region();
    setBackground(right, Color.BLUE);
    right.setPrefSize(200, 500);

    inner.setCenter(top);
    inner.setBottom(bottom);

    outer.setCenter(inner);
    outer.setRight(right);

    Scene s = new Scene(outer);
    primaryStage.setScene(s);
    primaryStage.show();

}
于 2016-12-11T23:10:52.520 回答