Nikita Medvedev
Nikita Medvedev

Reputation: 13

How to block a main window in JavaFX

There is a button in a scene of the main window. When it's clicked, the new window is created, according following code:

public static void create()
{
    Stage stage = new Stage();
    AnchorPane pane = new AnchorPane();
    //Here i add some into pane
    stage.setScene(new Scene(pane));
    stage.setWidth(500);
    stage.setHeight(600);
    stage.show();
}

I'd like the main window will remain blocked (i.e. an user won't be able to click on buttons, type text, resize or interact with it with other ways) until the additional window is closed.

Upvotes: 1

Views: 911

Answers (1)

Vivek Rao
Vivek Rao

Reputation: 26

Here is a link that shows exactly what you're looking for: http://www.javafxtutorials.com/tutorials/creating-a-pop-up-window-in-javafx/

Here is the main part of the code you need to add:

stage.initModality(Modality.APPLICATION_MODAL);
stage.initOwner(btn1.getScene().getWindow());
stage.showAndWait(); // This forces the program to pay attention ONLY to this popup window until its closed

Hope this helps.

Upvotes: 1

Related Questions