0

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);
    }
}
Cluster
  • 5,457
  • 1
  • 25
  • 36
  • Maybe this can help, it loads an FXML file in a AnchorPane: http://stackoverflow.com/questions/14265697/bind-width-and-height-of-dynamically-loaded-fxml – Perneel Feb 24 '13 at 14:59

1 Answers1

7

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 new Scene and call stage.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.

jewelsea
  • 150,031
  • 14
  • 366
  • 406