Open new window from button

2

I want to create a new window when the user clicks on a certain button, while this new window is open, the main window can not be used. How can I do this in JAVAFX?

I thought about doing the following sequence of commands in the button's OnAction function:

Stage s1 = new Stage();
        Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml"));
        Scene scene = new Scene(root);

        s1.setScene(scene);
        s1.show(); 

However, this leaves the main Stage (which is in the start method in the main class) still operative.

    
asked by anonymous 19.09.2017 / 15:14

1 answer

2

When creating your new stage, you need to put the other stage as its creator and then make the window "modal".

newStage.initOwner(parentStage);
newStage.initModality(Modality.APPLICATION_MODAL);
    
19.09.2017 / 15:31