简体   繁体   English

如何在 JavaFX 中阻止主窗口

[英]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 (ie 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.我希望主窗口将保持阻塞状态(即用户将无法单击按钮、键入文本、调整大小或以其他方式与其交互),直到附加窗口关闭。

Here is a link that shows exactly what you're looking for: http://www.javafxtutorials.com/tutorials/creating-a-pop-up-window-in-javafx/这是一个链接,可以准确显示您要查找的内容: 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.希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM