Module javafx.graphics
Package javafx.animation

# Class Timeline

java.lang.Object
javafx.animation.Animation
javafx.animation.Timeline

public final class Timeline extends Animation
A `Timeline` can be used to define a free form animation of any `WritableValue`, for example, all `JavaFX Properties`.

A `Timeline`, defined by one or more `KeyFrame`s, processes individual `KeyFrame`s sequentially, in the order specified by `KeyFrame.time`. The animated properties, defined as key values in `KeyFrame.values`, are interpolated to/from the targeted key values at the specified time of the `KeyFrame` to `Timeline`'s initial position, depends on `Timeline`'s direction.

`Timeline` processes an individual `KeyFrame` at or after the specified time interval elapsed, it does not guarantee the exact time when a `KeyFrame` is processed.

If a `KeyFrame` is not provided for the `time==0s` instant, one will be synthesized using the target values that are current at the time `Animation.play()` or `Animation.playFromStart()` are called.

It is not possible to change the `keyFrames` of a running `Timeline`. If the value of `keyFrames` is changed for a running `Timeline`, it has to be stopped and started again to pick up the new value.

The `Animation.cycleDurationProperty()` will be set to the largest time value of Timeline's keyFrames.

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.

Since:
  JavaFX 2.0
See Also:
  - `Animation`
  - `KeyFrame`
  - `KeyValue`

- ## Property Summary

  ### Properties declared in class javafx.animation.Animation

  `autoReverse, currentRate, currentTime, cycleCount, cycleDuration, delay, onFinished, rate, status, totalDuration`

- ## Nested Class Summary

  ## Nested classes/interfaces declared in class javafx.animation.Animation

  `Animation.Status`

- ## Field Summary

  ### Fields declared in class javafx.animation.Animation

  `INDEFINITE`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `Timeline()`
  Creates a `Timeline` with no key frames.
  `Timeline(double targetFramerate)`
  Creates a `Timeline` with no key frames and a target framerate.
  `Timeline(double targetFramerate, KeyFrame... keyFrames)`
  Creates a `Timeline` with the provided key frames and a target framerate.
  `Timeline(KeyFrame... keyFrames)`
  Creates a `Timeline` with the provided key frames.

- ## Method Summary

  Modifier and Type
  Method
  Description
  `final ObservableList<KeyFrame>`
  `getKeyFrames()`
  Returns the `KeyFrames` of this `Timeline`.

  ### Methods declared in 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, stop, totalDurationProperty`

  ### Methods declared in class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- ## Constructor Details

  - ### Timeline

    public Timeline(double targetFramerate, KeyFrame... keyFrames)
    Creates a `Timeline` with the provided key frames and a target framerate. The key frames do not need to be ordered.
    Parameters:
      `targetFramerate` - the custom target frame rate for this `Timeline`
      `keyFrames` - the keyframes of this `Timeline`

  - ### Timeline

    public Timeline(KeyFrame... keyFrames)
    Creates a `Timeline` with the provided key frames. The key frames do not need to be ordered.
    Parameters:
      `keyFrames` - the keyframes of this `Timeline`

  - ### Timeline

    public Timeline(double targetFramerate)
    Creates a `Timeline` with no key frames and a target framerate.
    Parameters:
      `targetFramerate` - the custom target frame rate for this `Timeline`

  - ### Timeline

    public Timeline()
    Creates a `Timeline` with no key frames.

- ## Method Details

  - ### getKeyFrames

    public final ObservableList<KeyFrame> getKeyFrames()
    Returns the `KeyFrames` of this `Timeline`.
    Returns:
      the `KeyFrames`