如果所有者最小化,则Javafx对话框(警报)不可见

gri*_*Flo 2 java dialog javafx javafx-8

如果所有者最小化,为什么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);
}
}
Run Code Online (Sandbox Code Playgroud)

如果你在2秒内最小化应用程序,然后再次最大化(2秒后)你没有看到对话框,但它以某种方式存在(舞台被锁定,直到你按esc或输入)

如果你没有最小化阶段,对话框会正确显示.

这是一个错误吗?我做错了吗?

编辑:系统是Windows 7,Java 1.8.0.66

Edit2:好的.它似乎真的是一个错误:https: //bugs.openjdk.java.net/browse/JDK-8151170

gri*_*Flo 5

找到了(可能的)解决方案.但这真的是一个很好的解决方案吗?

在显示警报之前,我执行以下行:

((Stage) alert.getOwner()).setIconified(false);
Run Code Online (Sandbox Code Playgroud)

如果有人有更好的主意我会删除我的答案.