2014-10-31 52 views
1

我有以下的代码,将我父布局:JavaFX的添加新的布局为母公司布局

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> 

回答

1

您可以使用您选择的另一个布局包两个布局您有:

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

另外,您可以重新设计所有的GUI并使用其他布局,如BorderPane,AnchorPane等。