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();
}
完全なコードはhttps://gist.github.com/bmesuere/9605866にあります。
なぜこれが機能しないのか (私の macbook では java 1.7.0_51 を使用) を知り、回避策の提案を得たいと思います。