JavaFX 8 Timeline Positioning Delays

I just invested three hours to search for the cause of a subtle bug in my application, until I discovered that my application was not wrong at all, but that Java FX 8 does not behave as the typical programmer would expect it. In particular, I’m talking about key frame animation with Timeline.

Timeline has methods to jump directly to the start of the animation, namely playFromStart, jump(Duration.ZERO), jump(Duration.ZERO) and jump("start"). As these methods are not marked as running in the background, one expects that they immediately execute the key frame at position Duration.ZERO. But they do not, not even when using Interpolator.DISCRETE. What these methods actually seem to do is to just prepare the timeline and pick up that key frame at the next frame. While this makes not much of a difference for most programs, it does really get into the way when there is a need to directly ask for the current property value immediately in the next code line, or at least within the same frame (e. g. due to property listeners or bindings). It’s just scary to see that the invalidation listeners do not fire immdiately!

Workaround

Whenever immediate execution of a key frame directly on the aimed cue point is needed, there apparently is no other way than executing it manually, i. e. looking it up in the time line’s list of key frames, getting the property values from the key frame, and set them.

Advertisements

About Markus Karg

Java Guru with +30 years of experience in professional software development. I travelled the whole world of IT, starting from Sinclair's great ZX Spectrum 48K, Commodore's 4040, over S/370, PCs since legendary XT, CP/M, VM/ESA, DOS, Windows (remember 3.1?), OS/2 WARP, Linux to Android and iOS... and still coding is my passion, and Java is my favourite drug!
This entry was posted in Java and tagged . Bookmark the permalink.