【发布时间】:2016-04-28 09:30:15
【问题描述】:
如果所有者被最小化,为什么 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 或 enter)
如果您不最小化阶段,对话框将正确显示。
这是一个错误吗?我做错了吗?
编辑: 系统是Windows 7,Java 1.8.0.66
编辑2: 行。看起来它真的是一个错误: https://bugs.openjdk.java.net/browse/JDK-8151170
【问题讨论】:
标签: java javafx dialog javafx-8