javafx VBox项目的java宽度未设置?
这是我写的代码,但没有为VBox项目设置宽度。所有的面板都是一样大小的。我需要一些帮助
private void initComponents() {
this.setPadding(new Insets(0,70,0,70));
this.setSpacing(10);
red1 = new StackPane();
red1.setStyle("-fx-background-color:red;");
red1.setPrefHeight(60);
red1.setPrefWidth(260);
this.setVgrow(red1, Priority.ALWAYS);
this.getChildren().add(red1);
red2 = new StackPane();
red2.setStyle("-fx-background-color:red;");
red2.setPrefHeight(60);
red2.setPrefWidth(240);
this.setVgrow(red2, Priority.ALWAYS);
this.getChildren().add(red2);
}
private StackPane red1;
private StackPane red2;
}
# 1 楼答案
所有窗格都会尝试布局并调整其子窗格的大小(如果可能),并且所有窗格的大小都由其父窗格根据其内容进行调整。有关更多信息,请阅读javadoc
所有窗格(
VBox
、StackPane
、FlowPane
、Pane
等)都打包到javafx.scene.layout
包中,这意味着这些窗格用于布置其他节点/控件实际尝试获取的形状被打包到
javafx.scene.shape
包中。使用它们,例如: