块所有者窗口 Java FX
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15625987/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Block owner window Java FX
提问by Kiva
I would like to block the owner window for a popup in JavaFX.
我想在 JavaFX 中阻止弹出窗口的所有者窗口。
I initialize my popup like this:
我像这样初始化我的弹出窗口:
popUp = new Popup();
popUp.getContent().add(content);
popUp.show(pane.getScene().getWindow());
With this, I can still work in the first window (pane window). I would like to disable this action and I would like the user just works in the popup.
有了这个,我仍然可以在第一个窗口(窗格窗口)中工作。我想禁用此操作,并且我希望用户只在弹出窗口中工作。
How to do this ?
这个怎么做 ?
Thanks.
谢谢。
回答by jewelsea
Use a Stageinstead of a Popup.
Before showing the stage, invoke stage.initModalityas either APPLICATION_MODALor WINDOW_MODAL, as appropriate. Also invoke stage.initOwnerto the parent window of your new stage so that it will appropriately block it for the WINDOW_MODAL
case.
在显示舞台之前,根据需要调用stage.initModality作为APPLICATION_MODAL或WINDOW_MODAL。同时调用stage.initOwner到你的新阶段的父窗口,这样它会根据WINDOW_MODAL
情况适当地阻止它。
Stage stage = new Stage();
stage.initModality(Modality.WINDOW_MODAL);
stage.initOwner(pane.getScene().getWindow());
stage.setScene(new Scene(content));
stage.show();
回答by user3434059
Thanks, optimal solution: example with FXML load file:
谢谢,最佳解决方案:FXML 加载文件示例:
@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);
}