【问题标题】:width is not setting for javafx VBox items?没有为 javafx VBox 项目设置宽度?
【发布时间】:2014-03-15 20:24:08
【问题描述】:

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

【问题讨论】:

    标签: java javafx javafx-2 vbox


    【解决方案1】:

    如果可能,所有窗格都会尝试对其子级进行布局和调整大小,并且所有窗格都由其父级通过尊重其内容来调整大小。阅读 javadoc 了解更多信息。

    所有窗格(VBoxStackPaneFlowPanePane 等)都打包到 javafx.​scene.​layout 包中,这意味着这些窗格用于布置其他节点/控件。

    您实际尝试获得的形状被打包到javafx.​scene.​shape 包中。例如,将它们用作:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-03
      • 2018-10-06
      • 1970-01-01
      • 2017-02-21
      • 2017-11-14
      • 2018-05-22
      相关资源
      最近更新 更多