2016-04-28 20 views
2

如果所有者最小化,爲什麼javafx中的對話框(警報)未正確顯示。如果所有者最小化,則Javafx對話框(警報)不可見

看看下面的代碼:

public class JavaFxSample2 extends Application { 

@Override 
public void start(Stage primaryStage) throws InterruptedException, ExecutionException { 
    primaryStage.setTitle("open alert in 2 seconds"); 
    Pane pane = new Pane(); 
    Button b = new Button("open dialog"); 
    b.setOnMouseClicked(event -> { 
     Task<Void> task = new Task<Void>() { 
      @Override 
      protected Void call() throws Exception { 
       Thread.sleep(2000); 
       return null; 
      } 
     }; 
     task.stateProperty().addListener((observable, oldValue, newValue) -> { 
      if (newValue == State.SUCCEEDED) { 
       Alert alert = new Alert(AlertType.INFORMATION, "Hello"); 
       alert.initOwner(primaryStage);     
       alert.showAndWait(); 
      } 
     }); 
     Thread thread = new Thread(task); 
     thread.start(); 
    }); 

    pane.getChildren().add(b); 

    Scene scene = new Scene(pane, 300, 275); 
    primaryStage.setScene(scene); 
    primaryStage.show(); 
} 

public static void main(String[] args) { 
    launch(args); 
} 
} 

如果您最大限度地減少2秒內的應用程序,然後再最大化(2秒後)你不看到對話框,但它的存在在某種程度上(在階段被鎖定,直到你按esc或輸入)

如果你不最小化階段對話框顯示正確。

這是一個錯誤?我做錯了嗎?

編輯: 系統是Windows 7,Java的1.8.0.66

EDIT2: 確定。它看起來像它的一個真正的bug: https://bugs.openjdk.java.net/browse/JDK-8151170

回答

5

找到一個(可能的)解決方案。 但這真的是一個很好的解決方案嗎?

顯示警報之前,我執行了以下行:

((Stage) alert.getOwner()).setIconified(false); 

如果有人有更好的主意,我會刪除我的答案。

0

如果您在顯示警報對話框之前添加此聲明,您將不必按EscEnter。這會釋放你凍結你的應用程序。

alert.initModality(Modality.NONE); 
+0

是的,我不必按esc或現在進入。但對話框也沒有顯示。所以答案是不正確的 – griFlo

0
DaoAlloyGeneral a = (DaoAlloyGeneral) tabelaAlloy.getSelectionModel().getSelectedItem(); 
      Alert alert = new Alert(AlertType.CONFIRMATION); 
      alert.setTitle(DaoCfgIdiomas.getTraducao("general.Confirmacao")); 
      alert.setHeaderText(DaoCfgIdiomas.getTraducao("general.Atencao")); 
      alert.setContentText(DaoCfgIdiomas.getTraducao("MainTabAlloy.msgDeletar") + " " +a.getNome()); 
      alert.setResizable(true); 
      alert.getDialogPane().setPrefSize(480, 320); 
      Optional<ButtonType> result = alert.showAndWait(); 
      if (result.get() == ButtonType.OK){ 

       DaoAlloyGeneral.deletarAlloy(a.getIdAlloy()); 
       tabelaAlloy.getItems().clear(); 
       tabelaAlloy.setItems(DaoAlloyGeneral.buscaTodos()); 
      } 

enter image description here

我不能瞭解它之前和現在的工作,停下來。 甲骨文jdk1.8.0_111 Linux機器

編輯:我發現這個問題,JVM參數 - Dcom.sun.javafx.isEmbedded =真 沒有這個選項,它的工作。