3

Is there a way to hide a stage after a specified time was passed like a few seconds or minutes ?

quartaela
  • 2,579
  • 16
  • 63
  • 99
  • This will help: http://stackoverflow.com/questions/13784333/platform-runlater-and-task-javafx – zmirc Sep 13 '13 at 08:39
  • I think that `Platform.runLater()` will be useless here cause I'm working with only main thread ?. Maybe I should work on animations, like : it will work with a timeline and will do nothing. – quartaela Sep 13 '13 at 08:55

1 Answers1

7

A solution with a Timeline:

final Stage stage = new Stage();
stage.setScene(new Scene(new Label("Hello")));
stage.show();
Timeline timeline = new Timeline();
timeline.getKeyFrames().add(new KeyFrame(Duration.seconds(10),
    new EventHandler<ActionEvent>() {

        @Override
        public void handle(ActionEvent event) {
            stage.hide();
        }
    }));
timeline.play();
gontard
  • 28,720
  • 11
  • 94
  • 117