Block parent stage until child stage closes

前端 未结 2 1811
后悔当初
后悔当初 2021-01-07 05:17

I have a controller on which an action event of my button opens a child stage. The issue is when I close the parent stage, the child stage also closes. I want to prevent par

相关标签:
2条回答
  • 2021-01-07 05:52

    Just set the following property to your stage object...

    stage.initModality(Modality.APPLICATION_MODAL);
    
    0 讨论(0)
  • 2021-01-07 06:04

    Set the followings:

    stage.initModality(Modality.WINDOW_MODAL);
    stage.initOwner(primaryStage);
    

    You can get the primaryStage by putting it to static variable in main class:

    public static Stage primaryStage;
    
    @Override
    public void start(Stage primaryStage) {
        this.primaryStage = primaryStage;
        ...
    }
    

    then

    stage.initOwner(MainApp.primaryStage);
    
    0 讨论(0)
提交回复
热议问题