I want to create a new window activated from a button, however while this new window was open, the main window can not be used.
Asked
Active
Viewed 1,002 times
-1
-
http://docs.oracle.com/javase/8/javafx/api/javafx/stage/Stage.html#initModality-javafx.stage.Modality- – James_D Sep 19 '17 at 12:32
-
How can I use it? – Leonardo Bortolini Sep 19 '17 at 12:35
-
Stage s1 = new Stage(); Parent root = FXMLLoader.load(getClass().getResource("FXMLDocument.fxml")); Scene scene = new Scene(root); s1.setScene(scene); s1.show(); This code is in an OnAction function of a button, the main window (where the button is) can not be used while this new window is open – Leonardo Bortolini Sep 19 '17 at 12:44
-
Possible duplicate of [How to create a modal window in JavaFX 2.1](https://stackoverflow.com/questions/10486731/how-to-create-a-modal-window-in-javafx-2-1) – findusl Sep 19 '17 at 13:12
2 Answers
0
When you make your new Stage newStage
you have to set the other window as it's owner and then set it to be window modal.
newStage.initOwner(parentStage);
newStage.initModality(Modality.APPLICATION_MODAL);

findusl
- 2,454
- 8
- 32
- 51
-
in my code of using `primaryStage` in the `start()` method, it turns out that `newStage.initOwner(parentStage)` did not really help of getting the output. not sure if it is due to my computer's settings – Qiyu Zhong Mar 07 '22 at 02:51
0
When create new stage and add required objects to it add:
newStage.initModality(Modality.APPLICATION_MODAL);
newStage.showAndWait();

Vanja Guliev
- 26
- 5