-1

Please help me to change gif file in javaFX ImageView and then switch to another scene after the gif is played once. When i do it like

i.setImage(url);
window.setScene(s);

the switch is done immediately. I don't see the gif shown on the screen. When i use

Thread.sleep(time),

between first two statements, the delay is realized, but gif does not change. How is it done correctly?

Juggernaut
  • 315
  • 1
  • 3
  • 9

1 Answers1

1

Do

i.setImage(url);
PauseTransition pause = new PauseTransition(Duration.millis(time));
pause.setOnFinished(e -> window.setScene(s));
pause.play();

You should never call Thread.sleep(...) on the FX Application Thread: it will prevent the UI from being rendered.

James_D
  • 201,275
  • 16
  • 291
  • 322