0

I currently use this code to change scenes in my JFX program:

public void addTaskFunction (ActionEvent event) throws IOException{
        Parent addTaskParent = FXMLLoader.load(getClass().getResource("/LogIn/AddDataToTaskManager.fxml"));
        Scene addTaskScene = new Scene(addTaskParent);
        Stage appStage = (Stage) ((Node) event.getSource()).getScene().getWindow();
        appStage.setScene(addTaskScene);
        appStage.setResizable(true);
        appStage.show();
    }

Using this code closes the previous stage and opens a new one on top. How can I make it so the previous stage does not close and this AddDataToTaskMaager.fxml opens on top of TaskManager.fxml

Thank you

KingKeyy
  • 59
  • 7
  • 2
    you need a new Stage or a Popup(if you want a popup...) instead of setting new content to the stage that is currently displayed. Problem here -> "Stage appStage = (Stage) ((Node) "event.getSource()).getScene().getWindow(); appStage.setScene(addTaskScene);" – kai Feb 21 '19 at 08:15

1 Answers1

0

I changed the code with tips from @kai

public void addTaskFunction (ActionEvent event) throws IOException{
        Parent addTaskParent = FXMLLoader.load(getClass().getResource("/LogIn/AddDataToTaskManager.fxml"));
        Scene addTaskScene = new Scene(addTaskParent);
        Stage stage = new Stage();
        stage.setTitle("Thank You");
        stage.setScene(addTaskScene);
        stage.show();
    }
KingKeyy
  • 59
  • 7
  • 1
    optional: you could also add: stage.initOwner(appStage) if you want the new Stage to be a Child of the appStage. – kai Feb 21 '19 at 08:34