Block owner window Java FX

后端 未结 2 1367
离开以前
离开以前 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:48

    Thanks, optimal solution: example with FXML load file:

    @Override
        public void start(Stage primaryStage) throws IOException {
            Parent root = FXMLLoader.load(getClass().getResource("DialogView.fxml"));
            primaryStage.initModality(Modality.APPLICATION_MODAL); // 1 Add one
            Scene scene = new Scene(root);        
            primaryStage.setScene(scene);
            primaryStage.initOwner(primaryStage.getScene().getWindow());// 2 Add two
            primaryStage.show();
    
        }
    
        public static void main(String[] args) {
            launch(args);
    
        }
    

提交回复
热议问题