i've created fxml files in anchor pane but everytime i click on the button i get the next fxml in a new frame i want it to open in the same frame
public void baropen(ActionEvent event) {
// handle the event here
BorderPane bp = new BorderPane();
bp.setPadding(new Insets(10, 50, 50, 50));
Stage stage = new Stage();
Scene scene ;
// scene= new Scene(root);
scene = new Scene(bp);
stage.setScene(scene);
stage.show();
try {
new RecBar().start(stage);
} catch (Exception ex) {
Logger.getLogger(RecController.class.getName()).log(Level.SEVERE, null,ex);
}
}
Just create a single
Stage
and when you want to replace the content of the stage with a new fxml, load the new fxml into a newScene
and callstage.setScene
.It's a theater metaphor - imagine you are watching a play - it's Romeo and Juliet, the curtain raises and you see the first scene (a plaza in Verona with a fountain). Later on, the curtain lowers, little men run around and change stuff, the curtain rises and you see a new scene (the balcony to Juliet's bedroom). The scene has changed, but the stage has not - there is just one stage and multiple scenes.