在动画的onFinished EventHandler中使用showAndWait不起作用

bme*_*ere 5 java animation javafx-2 eventhandler

在JavaFx中,我想在动画结束后显示模态对话框.出于某种原因,在动画结束后执行的EventHandler中调用showAndWait不起作用.显示一个新窗口,但似乎内部没有任何内容.

此示例演示了此问题:

public void start(Stage primaryStage) {
    Rectangle rect = RectangleBuilder.create().width(200).height(200).fill(Color.RED).build();

    StackPane root = new StackPane();
    root.getChildren().add(rect);

    Timeline animation = new Timeline();
    animation.getKeyFrames().addAll(
            new KeyFrame(new Duration(1000),
                         new KeyValue(rect.widthProperty(), 100),
                         new KeyValue(rect.heightProperty(), 100)),
            new KeyFrame(new Duration(2000),
                         new KeyValue(rect.widthProperty(), 300),
                         new KeyValue(rect.heightProperty(), 300))
    );
    animation.setOnFinished(new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent t) {
            Stage stage = new Stage();
            StackPane pane = new StackPane();
            pane.getChildren().add(new Label("Hello world"));
            stage.setScene(new Scene(pane, 100, 100));
            stage.showAndWait();
        }
    });
    animation.setCycleCount(1);

    Scene scene = new Scene(root, 300, 300);
    primaryStage.setScene(scene);
    primaryStage.show();

    animation.play();
}
Run Code Online (Sandbox Code Playgroud)

完整代码可以在https://gist.github.com/bmesuere/9605866找到

我想知道为什么这不起作用(在我的Macbook上使用java 1.7.0_51)并获得解决方法的建议.

bme*_*ere 1

我已将其报告为 JavaFX 中的错误(Jira 问题)。

该问题的评论:

问题是在处理脉冲时调用 showAndWait() 时不会安排后续脉冲。

这在 Java 8u20 中已“修复”。现在抛出异常。变化可以从这里看出。