'getChildren method in Parent - JavaFX

I wrote a code that display a window in JavaFX, and I loaded XML file that gives me a number of Buttons that I need to create in run-time.

I used Parent as the root and I can't do Parent.getChildren().add(...) as Pane.getChildren().add(...)

    public void start(Stage primaryStage) throws Exception
{
    FXMLLoader fxmlLoader = new FXMLLoader();
    URL url = 
    this.getClass().getResource("/resources/UI.fxml");
    fxmlLoader.setLocation(url);
    Parent root = (Parent)fxmlLoader.load(url.openStream());
    primaryStage.setTitle("N In A Row");
    primaryStage.setScene(new Scene(root, 1000, 800));
    m_GameController = 
    (MainController)fxmlLoader.getController();
    primaryStage.show();
}


Solution 1:[1]

Use scene builder to add a container to your application then add the container variable in your application controller class. Now use the created container and add as much child as you want in it through the controller.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 shemar edwards