2017-10-06 68 views
1

主窗口的场景中有一个按钮。当它被点击,创建新的窗口,按照下面的代码:如何在JavaFX中阻止主窗口

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(); 
} 

我想在主窗口,解除封锁(即用户将无法点击按钮,输入文字,调整或与其他方式进行交互),直到附加窗口关闭。

+0

https://docs.oracle.com/javase/9​​/docs/api/javafx/stage/Stage.html#initModality-javafx.stage.Modality- –

回答

1

这里是一个链接,显示你正在寻找什么:这里http://www.javafxtutorials.com/tutorials/creating-a-pop-up-window-in-javafx/

是你需要添加代码的主要部分:

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 

希望这有助于。