JDK-8095631 : Using showAndWait in the onFinished EventHandler of an Animation doesn't work
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 7u51
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2014-03-18
  • Updated: 2015-06-12
  • Resolved: 2014-03-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8u20Fixed
Related Reports
Relates :  
Description
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.

This example demonstrates the issue:
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();
}
Comments
Changeset: http://hg.openjdk.java.net/openjfx/8u-dev/rt/rev/c5ebcc5268b4
20-03-2014

Thanks, that's what I would have thought. +1
19-03-2014

The fact that it gets called with the inPulse flag set means that no other pulse will be scheduled until the showAndWait returns, so I think that rules out pretty much everything that's done within the pulse.
19-03-2014

Could this break possibly legitimate uses of showAndWait? I ran all of the regression tests that I could think of with your patch and it looks good, but we need to make sure. The following cases should certainly be blocked from running showAndWait: 1) pulse listeners 2) animation callbacks: onFinished, AnimationTimer 3) property handlers (if called from layout or CSS) Are there other cases where user code could be called with the "inPulse" flag set where it still might be OK to call showAndWait? I don't think so, but wanted to ask the question.
19-03-2014

Kevin, please review: http://cr.openjdk.java.net/~msladecek/rt-36256/webrev/ I think we need to throw Exception when showAndWait is called outside of event processing. Otherwise, the pulse call would wait for showAndWait to finish, which might break animations, css, layout or synchronization. Also, no subsequent pulse will be scheduled.
19-03-2014

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