Java examples for JavaFX:Animation
fade Transition in JavaFX Animation
//package com.java2s; import javafx.animation.FadeTransition; import javafx.animation.SequentialTransition; import javafx.animation.SequentialTransitionBuilder; import javafx.event.ActionEvent; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.util.Duration; public class Main { public static SequentialTransition fadeTransition(final ImageView iv, final Image img) { FadeTransition fadeOutTransition/*w w w . j a v a2s . c o m*/ = new FadeTransition(Duration.seconds(0.4), iv); fadeOutTransition.setFromValue(1.0); fadeOutTransition.setToValue(0.3); fadeOutTransition.setOnFinished((ActionEvent arg0) -> { iv.setImage(img); }); FadeTransition fadeInTransition = new FadeTransition(Duration.seconds(0.2), iv); fadeInTransition.setFromValue(0.3); fadeInTransition.setToValue(1.0); SequentialTransition sequentialTransition = SequentialTransitionBuilder .create() .children(fadeOutTransition, fadeInTransition) .build(); return sequentialTransition; } }