package bug; import javafx.animation.AnimationTimer; import javafx.animation.FadeTransition; import javafx.animation.SequentialTransition; import javafx.application.Application; import javafx.application.Platform; import javafx.event.ActionEvent; import javafx.event.EventHandler; import javafx.scene.Scene; import javafx.scene.control.Button; import javafx.scene.control.Label; import javafx.scene.layout.StackPane; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javafx.util.Duration; /** * * @author akouznet */ public class Bug extends Application { private static final int FADE_TIMEOUT = 150; private SequentialTransition fadeSequentialTransition = null; int counter = 0; @Override public void start(Stage primaryStage) { Label navSymbol = new Label("navSymbol"); Label time = new Label("time"); StackPane parent = new StackPane(navSymbol); Button btn = new Button(); btn.setText("Test"); btn.setOnAction(new EventHandler() { @Override public void handle(ActionEvent event) { test(); Platform.runLater(() -> test()); new AnimationTimer() { int j = 0; @Override public void handle(long now) { if (j < 99) { test(); j++; } parent.setVisible(true); } }.start(); } private void test() { for (int i = 0; i < 3; i++) { if (fadeSequentialTransition != null) { fadeSequentialTransition.stop(); } FadeTransition fadeOut = new FadeTransition(Duration.millis(FADE_TIMEOUT * navSymbol.getOpacity())); fadeOut.setFromValue(navSymbol.getOpacity()); fadeOut.setToValue(0); fadeOut.setOnFinished(e -> navSymbol.setText(Integer.toString(counter++))); FadeTransition fadeIn = new FadeTransition(Duration.millis(FADE_TIMEOUT)); fadeIn.setFromValue(0); fadeIn.setToValue(1); fadeSequentialTransition = new SequentialTransition(navSymbol, fadeOut, fadeIn); fadeSequentialTransition.play(); fadeSequentialTransition.setOnFinished(e -> System.out.println("Finished")); time.textProperty().bind(fadeSequentialTransition.currentTimeProperty().asString()); parent.setVisible(!parent.isVisible()); } } }); VBox root = new VBox(btn, parent, time); Scene scene = new Scene(root, 300, 250); primaryStage.setTitle("Hello World!"); primaryStage.setScene(scene); primaryStage.show(); } /** * @param args the command line arguments */ public static void main(String[] args) { launch(args); } }