How to create a modal window in JavaFX 2.1

In my opinion this is not good solution, because parent window is all time active.
For example if You want open window as modal after click button…

private void clickShow(ActionEvent event) {
    Stage stage = new Stage();
    Parent root = FXMLLoader.load(
        YourClassController.class.getResource("YourClass.fxml"));
    stage.setScene(new Scene(root));
    stage.setTitle("My modal window");
    stage.initModality(Modality.WINDOW_MODAL);
    stage.initOwner(
        ((Node)event.getSource()).getScene().getWindow() );
    stage.show();
}

Now Your new window is REALY modal – parent is block.
also You can use

Modality.APPLICATION_MODAL

Leave a Comment