Home > other >  Reload Java Fx Scene?
Reload Java Fx Scene?

Time:02-18

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

CodePudding user response:

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

  • Related