Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8095631

Using showAndWait in the onFinished EventHandler of an Animation doesn't work

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 8u20
    • 7u51
    • javafx
    • None
    • Mac os 10.9.2

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

      Attachments

        Issue Links

          Activity

            People

              msladecek Martin Sládeček
              duke J. Duke
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported: