Block owner window Java FX

后端 未结 2 1360
离开以前
离开以前 2020-12-29 12:53

I would like to block the owner window for a popup in JavaFX.

I initialize my popup like this:

popUp = new Popup();
popUp.getContent().add(content);
         


        
2条回答
  •  爱一瞬间的悲伤
    2020-12-29 13:46

    Use a Stage instead of a Popup.

    Before showing the stage, invoke stage.initModality as either APPLICATION_MODAL or WINDOW_MODAL, as appropriate. Also invoke stage.initOwner to the parent window of your new stage so that it will appropriately block it for the WINDOW_MODAL case.

    Stage stage = new Stage();
    stage.initModality(Modality.WINDOW_MODAL);
    stage.initOwner(pane.getScene().getWindow());
    stage.setScene(new Scene(content));
    stage.show();
    

提交回复
热议问题