【问题标题】:JavaFX add new layout into parent layoutJavaFX 将新布局添加到父布局中
【发布时间】:2014-10-31 12:28:10
【问题描述】:

我有以下代码来设置我的父布局:

public void start(Stage primaryStage) {
    try {
        Parent root = FXMLLoader.load(getClass().getResource("/view/BaseStructure.fxml"));
        Scene scene = new Scene(root);
        scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
        primaryStage.setScene(scene);
        primaryStage.show();
    } catch(Exception e) {
        e.printStackTrace();
    }
}

我想向父布局的right 添加另一个布局。我怎样才能在主课上做到这一点?

这是我的父布局 .fxml 文件的样子:

<VBox prefHeight="400.0" prefWidth="640.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="application.Main">
   //more code here
   <right>
     //need my second layout here
   </right>
</VBox>

【问题讨论】:

    标签: java javafx


    【解决方案1】:

    您可以使用您选择的另一个布局,其中包含您拥有的两个布局:

    HBox hbox = new HBox(10);
    hbox.getChildren().addAll(getMySecondLayout(), root);
    Scene scene = new Scene(hbox);
    

    或者,您可以重新设计所有 GUI 并使用其他布局,例如 BorderPaneAnchorPane 等。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-20
      相关资源
      最近更新 更多