My scene consists only of an ImageView displaying an image. I would like to change the image to black (the assigned color of the scene), and then after a while it will disappear again from black to the image. I found FadeTransition very suitable for this purpose. This is part of my code:
FadeTransition ft1 = new FadeTransition(Duration.millis(2000), myImageView);
ft1.setFromValue(1.0);
ft1.setToValue(0.0);
ft1.play();
FadeTransition ft2 = new FadeTransition(Duration.millis(2000), myImageView);
ft2.setFromValue(0.0);
ft2.setToValue(1.0);
ft2.play();
My problem is that it ft1.play()is asynchronous, so the code below will start to execute before exiting ft1.play(). As a result, I see only the second transition. How can I wait for the first transition to complete and then launch the second transition? I can not put the thread to sleep between them, because this is the main javafx thread (tried and did not work).
onFinishedProperty() , while . :
boolean isTransitionPlaying;
FadeTransition ft = new FadeTransition(Duration.millis(2000), iv);
ft.setFromValue(1.0);
ft.setToValue(0.0);
ft.onFinishedProperty().set(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent actionEvent) {
transitionPlaying = false;
}
});
transitionPlaying = true;
ft.play();
while (transitionPlaying == true)
{
System.out.println("still waiting...");
}
FadeTransition ft2 = new FadeTransition(Duration.millis(2000), iv);
ft2.setFromValue(0.0);
ft2.setToValue(1.0);
ft2.play();
?