在动画的onFinished事件处理程序使用showAndWait不起作用 [英] Using showAndWait in the onFinished EventHandler of an Animation doesn't work

查看:2049
本文介绍了在动画的onFinished事件处理程序使用showAndWait不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JavaFX中,我希望有一个动画结束后显示一个模式对话框。出于某种原因,是可以获得动画结束后执行的事件处理程序调用showAndWait不起作用。显示一个新窗口,但似乎没有什么是它里面的绘制。

In JavaFx, I want to show a modal dialog after an animation ends. For some reason, calling showAndWait in the EventHandler that gets executed after the animation ends doesn't work. A new window is shown, but it seems like nothing is drawn inside it.

此示例演示问题:

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();
}

满code可以在 https://gist.github.com/bmesuere/9605866 找到

我想知道为什么不工作(使用Java 1.7.0_51我的MacBook),并得到一个解决办法的建议。

I'd like to know why this doesn't work (on my macbook using java 1.7.0_51) and get suggestions for a workaround.

推荐答案

我已举报此作为JavaFX的(错误的 JIRA问题)。

I have reported this as a bug in JavaFX (Jira issue).

这是该问题的评论:

的问题是,当showAndWait()正在被处理时脉冲被称为没有后续脉冲定

The problem is that no subsequent pulse is scheduled when showAndWait() is called while pulse is being processed.

这是在Java中8u20固定。一个例外是现在抛出。变化可以在这里看到

This was 'fixed' in Java 8u20. An exception is now thrown. Changes can be seen here.

这篇关于在动画的onFinished事件处理程序使用showAndWait不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆