- java.lang.Object
-
- javafx.animation.Animation
-
- javafx.animation.Timeline
-
public final class Timeline extends Animation
ATimeline
can be used to define a free form animation of anyWritableValue
, for example, allJavaFX Properties
.A
Timeline
, defined by one or moreKeyFrame
s, processes individualKeyFrame
sequentially, in the order specified byKeyFrame.time
. The animated properties, defined as key values inKeyFrame.values
, are interpolated to/from the targeted key values at the specified time of theKeyFrame
toTimeline
's initial position, depends onTimeline
's direction.Timeline
processes individualKeyFrame
at or after specified time interval elapsed, it does not guarantee the timing whenKeyFrame
is processed.The
Animation.cycleDurationProperty()
will be set to the largest time value of Timeline's keyFrames.If a
KeyFrame
is not provided for thetime==0s
instant, one will be synthesized using the target values that are current at the timeAnimation.play()
orAnimation.playFromStart()
is called.It is not possible to change the
keyFrames
of a runningTimeline
. If the value ofkeyFrames
is changed for a runningTimeline
, it has to be stopped and started again to pick up the new value.A simple Timeline can be created like this:
final Timeline timeline = new Timeline(); timeline.setCycleCount(2); timeline.setAutoReverse(true); timeline.getKeyFrames().add(new KeyFrame(Duration.millis(5000), new KeyValue (node.translateXProperty(), 25))); timeline.play();
This Timeline will run for 10s, animating the node by x axis to value 25 and then back to 0 on the second cycle.
Warning: A running Timeline is being referenced from the FX runtime. Infinite Timeline might result in a memory leak if not stopped properly. All the objects with animated properties would not be garbage collected.
-
-
Property Summary
-
Properties inherited from class javafx.animation.Animation
autoReverse, currentRate, currentTime, cycleCount, cycleDuration, delay, onFinished, rate, status, totalDuration
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javafx.animation.Animation
Animation.Status
-
-
Field Summary
-
Fields inherited from class javafx.animation.Animation
INDEFINITE
-
-
Method Summary
Modifier and Type Method Description ObservableList<KeyFrame>
getKeyFrames()
Returns theKeyFrames
of thisTimeline
.void
stop()
Stops the animation and resets the play head to its initial position.-
Methods inherited from class javafx.animation.Animation
autoReverseProperty, currentRateProperty, currentTimeProperty, cycleCountProperty, cycleDurationProperty, delayProperty, getCuePoints, getCurrentRate, getCurrentTime, getCycleCount, getCycleDuration, getDelay, getOnFinished, getRate, getStatus, getTargetFramerate, getTotalDuration, isAutoReverse, jumpTo, jumpTo, onFinishedProperty, pause, play, playFrom, playFrom, playFromStart, rateProperty, setAutoReverse, setCycleCount, setCycleDuration, setDelay, setOnFinished, setRate, setStatus, statusProperty, totalDurationProperty
-
-
-
-
Constructor Detail
-
Timeline
public Timeline(double targetFramerate, KeyFrame... keyFrames)
The constructor ofTimeline
. This constructor allows to define aAnimation.targetFramerate
.- Parameters:
targetFramerate
- The custom target frame rate for thisTimeline
keyFrames
- The keyframes of thisTimeline
-
Timeline
public Timeline(KeyFrame... keyFrames)
The constructor ofTimeline
.- Parameters:
keyFrames
- The keyframes of thisTimeline
-
Timeline
public Timeline(double targetFramerate)
The constructor ofTimeline
. This constructor allows to define aAnimation.targetFramerate
.- Parameters:
targetFramerate
- The custom target frame rate for thisTimeline
-
Timeline
public Timeline()
The constructor ofTimeline
.
-
-
Method Detail
-
getKeyFrames
public final ObservableList<KeyFrame> getKeyFrames()
Returns theKeyFrames
of thisTimeline
.- Returns:
- the
KeyFrames
-
-