如果所有者最小化,爲什麼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
是的,我不必按esc或現在進入。但對話框也沒有顯示。所以答案是不正確的 – griFlo