Open new window from button

Asked

Viewed 1,118 times

2

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

I thought to make the following command sequence in the button Onaction function:

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

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

But this leaves the main stage (which is in the start method in the main class) still operative.

1 answer

2


When creating your new Stage, you need to place the other Stage as your creator and after that turn the window into "modal".

newStage.initOwner(parentStage);
newStage.initModality(Modality.APPLICATION_MODAL);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.