2017-10-06 69 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 

希望這有助於。