@Override
public void start(Stage primaryStage) throws Exception {
SimpleStringProperty testProperty = new SimpleStringProperty();
Timeline timeline = new Timeline(new KeyFrame(Duration.millis(1000), new KeyValue(testProperty, "1234")));
timeline.setCycleCount(Timeline.INDEFINITE);
SimpleIntegerProperty actualCycleProperty = new SimpleIntegerProperty(0);
timeline.currentTimeProperty().addListener((observable, oldValue, newValue) -> {
boolean smaller = newValue.toMillis() < oldValue.toMillis();
boolean evenCycleCount = actualCycleProperty.get() % 2 == 0;
if ((timeline.isAutoReverse() && !evenCycleCount && !smaller)
|| ((evenCycleCount || !timeline.isAutoReverse()) && smaller)) {
actualCycleProperty.set(actualCycleProperty.get() + 1);
}
});
actualCycleProperty.addListener((observable, oldValue, newValue) -> {
System.out.println(newValue);
});
timeline.play();
}