javafx VBox项目的宽度未设置?
这是我编写的代码,但没有为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
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));