Garmaine Staff asked 2 years ago

I have written a small program that has several scenes in javafx. I thought that I would press a button in one scene, then it should open the other scene and then execute my method. Unfortunately, my method is always executed first and then the new scene is displayed. Can someone help me? I've been looking for a solution for hours.

Here is the used onAction-code:

    public void switchToProgress(ActionEvent event) throws IOException{
        Parent progress = FXMLLoader.load(getClass().getResource("copyProgress.fxml"));
        Scene copyScene = new Scene(progress);
        Stage progresswindow = (Stage) ((Node)event.getSource()).getScene().getWindow();
        progresswindow.setScene(copyScene);
        progresswindow.show();

        myMethod();
    }