窗格中的填充宽度
有一个像它一样的根源和一个像它的孩子一样。根目录随舞台一起调整大小。如何实现自动调整根目录的大小以填充宽度?任何宽度都应该是可能的。在没有属性绑定的情况下是否可能?Pane
GridPane
GridPane
情况如下:
- 根(黄色)是 的根,因此它填充 了 的宽度和高度。
Pane
Scene
Stage
- A(绿色),其中一行和 3 个腔作为根的子项。
GridPane
- 该行应具有固定的高度。
- 第一列和第三列应具有恒定大小
- 中间列应增长到最大
- 应填充其父项的宽度
GridPane
法典:
@Override
public void start(Stage primaryStage) throws Exception {
// Resizes with the stage
final Pane root = new Pane();
root.setStyle("-fx-background-color: yellow");
// grid: 1 row, 3 colums
// should have a constant height and should grow in width to fill parent pane
final GridPane gridPane = new GridPane();
root.getChildren().add(gridPane);
gridPane.setStyle("-fx-background-color: green");
gridPane.setGridLinesVisible(true);
final RowConstraints row = new RowConstraints(100); // constant height = 100
final ColumnConstraints col1 = new ColumnConstraints(100, Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE);
// should grow as much as possible in width
final ColumnConstraints col2 = new ColumnConstraints(200, Control.USE_COMPUTED_SIZE, Double.MAX_VALUE);
final ColumnConstraints col3 = new ColumnConstraints(100, Control.USE_COMPUTED_SIZE, Control.USE_COMPUTED_SIZE);
gridPane.getRowConstraints().add(row);
gridPane.getColumnConstraints().addAll(col1, col2, col3);
final Scene scene = new Scene(root);
primaryStage.setScene(scene);
primaryStage.setWidth(600);
primaryStage.setHeight(400);
primaryStage.show();
}