-2

I want to reload my Scene of the Java Fx project.

So i created a button, which has an Fx-ID

now i want to create something, that reloads the whole fx scene after pressing the button...

How is this possible.?

@Override
public void start(Stage stage) throws IOException {
    FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));

    Scene scene = new Scene(fxmlLoader.load());
    stage.setTitle("!");
    stage.setScene(scene);
    stage

this is my scene

1 Answers1

-1

Try

Stage close = (Stage) restart.getScene().getWindow();
    close.close();
    Stage stage = new Stage();
    FXMLLoader fxmlLoader = new FXMLLoader(HelloApplication.class.getResource("hello-view.fxml"));

    Scene scene = new Scene(fxmlLoader.load());
    stage.setTitle("!");
    stage.setScene(scene);
    stage.show();
}

this should help to close your stage. you will also create another stage, with deleted inputs

SIMCHE
  • 22
  • 3
  • Why create a new `Scene` and new `Stage`? – James_D Feb 17 '22 at 16:18
  • i tried to close the old scene and create a new one at the same time, which is the new scene to play a game for a example. – SIMCHE Feb 17 '22 at 16:21
  • Why though? Why not just reuse the existing ones? – James_D Feb 17 '22 at 16:21
  • that true, also possible... thank you – SIMCHE Feb 17 '22 at 16:22
  • 1
    I seriously don’t understand why the OP thinks this answer is correct. What is wrong with `FXMLLoader fxmlLoader = new FXMLLoader(…);` and `restart.getScene().setRoot(fxmlLoader.load());`. Nowhere does the question say anything about creating new windows. – James_D Feb 17 '22 at 16:28