Q:

Timeline animation not working as intended

It's been a long time I haven't been here, well until now of course.
The question is, there is a piece of code that I'm desperately trying to make it work:
private Timeline timeline = createTimeline();
timeline.play();
public Timeline createTimeline() {
Timeline timeline = new Timeline();
timeline.setDelay(new Duration(1000));
timeline.getKeyFrames().addAll(
        new KeyFrame(Duration.ZERO, new KeyValue(imageProperty(), moveOneStep())),
        new KeyFrame(new Duration(250), new KeyValue(imageProperty(), moveOneStep())));
timeline.setCycleCount(Timeline.INDEFINITE);
return timeline;
}
public Image moveOneStep() {
    return getNextImage();
}
private Image getNextImage() {
    imgCount++;
    if (imgCount > 2)
        imgCount %= 3;
    return images[imgCount];
}

The problem is, though I have tried both setting the cycle count to indefinite before and after the keyframes, it doesn't seem to be repeating at all. I am a little confused on this one.
Thanks in advance.

A:

It seems you need to define a "closing keyframe" so that the the keyframe just before the last one can play. I doubt, is this "by design" or a bug.
timeline.getKeyFrames().addAll(
        new KeyFrame(Duration.ZERO, new KeyValue(imageProperty(), moveOneStep())),
        new KeyFrame(new Duration(250), new KeyValue(imageProperty(), moveOneStep())),
        new KeyFrame(new Duration(500));

You can track the changes of any property with ChangeListener, for instance:
imageProperty().addListener(new ChangeListener<Image>() {
    @Override
    public void changed(ObservableValue<? extends Image> observable, Image oldValue, Image newValue) {
        System.out.println("imageProperty oldValue " + oldValue);
        System.out.println("imageProperty newValue " + newValue);
        System.out.println("");
    }
});

