Include a fxml via code by a controller

Asked

Viewed 146 times

0

Hello, I have the following question. I have two fxml: Userlist.fxml and Userproperties.fxml. And I need to include Userlist within Userproperties, but it can’t be by fxml, because it won’t always happen, only if a certain condition is true. Would anyone have any idea how to do this by the controller?

Thank you.

1 answer

0

You could add both in a stackpane in fxml itself and leave it hidden, only showing when the condition is met, you could even use the visibility property and make a bind with this condition.

Another way would be to add fxml to Scene or a panel.

    FXMLLoader loader = new FXMLLoader(getClass().getClassLoader().getResource(caminho));
    Pane parent;
    try {
        parent = (Pane) loader.load();
        //adicionar a scene ou pane
        scene.add(parent);
    } catch (IOException ex) {
        Logger.getLogger(AplicacaoController.class.getName()).log(Level.SEVERE, null, ex);
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.