Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
javafx VBox项目的宽度未设置?_Java_Javafx 2_Vbox - Fatal编程技术网

javafx VBox项目的宽度未设置?

javafx VBox项目的宽度未设置?,java,javafx-2,vbox,Java,Javafx 2,Vbox,这是我编写的代码,但没有为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.setPrefHeigh

这是我编写的代码,但没有为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;
}

如果可能,所有窗格都会尝试布局和调整其子窗格的大小,并且所有窗格的父窗格都会根据其内容调整其大小。有关更多信息,请阅读javadoc

所有窗格(
VBox
StackPane
FlowPane
Pane
等)都打包到
javafx中。​场景​布局
包,表示这些窗格用于布局其他节点/控件

您实际尝试获取的形状被打包到
javafx中。​场景​形状
包装。使用它们,例如:

red1.getChildren().add(new Rectangle(200, 100, Color.YELLOW));
...
red2.getChildren().add(new Circle(30, Color.BLUE));