in my project, I need to copy the content of an specific HBox from some FXML files acording to the menu clicked, and put it in the HBox related to the content of the main page.
Bellow you can see the hierarchy of the project, and this aproach's goal is to have a global page, changing only the content of this HBox. The HBox in the main and in the other pages has the ID "conteudo".
I was able to copy and paste the content, but it can only happen once. After caling clear() or removeAll() once, it does not work anymore. There is no error also, and I checked and "conteudo" is still there after the remove/clear of it's childrens, any idea why it happens only once?
Note 1: Using ((HBox) fxmlAldeia.lookup("#conteudo")).getChildren() I get acess to the content inside "conteudo".
Note 2: getCenter does not help, because I get only a part of the center.
Note 3: I can not build the content of "conteudo" using java. I do that using Scenebuilder to speedUp, thats why I need to load it from the FXML.
Hierarchy:
Código
package simulador;
public class Aldeia extends Application {
private static Scene sceneAldeia;
protected static BorderPane fxmlAldeia;
protected static BorderPane fxmlEdfPrincipal;
public void start(Stage primaryStage) throws Exception {
primaryStage.setTitle("TW Fake");
fxmlAldeia = FXMLLoader.load(getClass().getResource("Aldeia.fxml"));
fxmlEdfPrincipal = FXMLLoader.load(getClass().getResource("EdfPrincipal.fxml"));
sceneAldeia = new Scene(fxmlAldeia);
primaryStage.setScene(sceneAldeia);
primaryStage.show();
}
public static void changeScreen(String src) throws IOException {
// limpa conteúdo
((HBox) fxmlAldeia.lookup("#conteudo")).getChildren().clear();
switch (src) {
case "aldeia":
((HBox) fxmlAldeia.lookup("#conteudo")).getChildren()
.addAll(((HBox) fxmlAldeia.lookup("#conteudo")).getChildren());
break;
case "edfPrincipal":
((HBox) fxmlAldeia.lookup("#conteudo")).getChildren()
.addAll(((HBox) fxmlEdfPrincipal.lookup("#conteudo")).getChildren());
break;
}
}
public static void main(String[] args) {
launch(args);
}
}