- java.lang.Object
- 
- javafx.animation.Animation
 
- 
- Direct Known Subclasses:
- Timeline,- Transition
 
 public abstract class Animation extends Object The classAnimationprovides the core functionality of all animations used in the JavaFX runtime.An animation can run in a loop by setting cycleCount. To make an animation run back and forth while looping, set theautoReverse-flag.Call play()orplayFromStart()to play anAnimation. TheAnimationprogresses in the direction and speed specified byrate, and stops when its duration is elapsed. AnAnimationwith indefinite duration (acycleCountofINDEFINITE) runs repeatedly until thestop()method is explicitly called, which will stop the runningAnimationand reset its play head to the initial position.An Animationcan be paused by callingpause(), and the nextplay()call will resume theAnimationfrom where it was paused.An Animation's play head can be randomly positioned, whether it is running or not. If theAnimationis running, the play head jumps to the specified position immediately and continues playing from new position. If theAnimationis not running, the nextplay()will start theAnimationfrom the specified position.Inverting the value of ratetoggles the play direction.- Since:
- JavaFX 2.0
- See Also:
- Timeline,- Transition
 
- 
- 
Property SummaryProperties Type Property Description BooleanPropertyautoReverseDefines whether thisAnimationreverses direction on alternating cycles.ReadOnlyDoublePropertycurrentRateRead-only variable to indicate current direction/speed at which theAnimationis being played.ReadOnlyObjectProperty<Duration>currentTimeDefines theAnimation's play head position.IntegerPropertycycleCountDefines the number of cycles in this animation.ReadOnlyObjectProperty<Duration>cycleDurationRead-only variable to indicate the duration of one cycle of thisAnimation: the time it takes to play from time 0 to the end of the Animation (at the defaultrateof 1.0).ObjectProperty<Duration>delayDelays the start of an animation.ObjectProperty<EventHandler<ActionEvent>>onFinishedThe action to be executed at the conclusion of thisAnimation.DoublePropertyrateDefines the direction/speed at which theAnimationis expected to be played.ReadOnlyObjectProperty<Animation.Status>statusThe status of theAnimation.ReadOnlyObjectProperty<Duration>totalDurationRead-only variable to indicate the total duration of thisAnimation, including repeats.
 - 
Nested Class SummaryNested Classes Modifier and Type Class Description static classAnimation.StatusThe possible states forstatus.
 - 
Field SummaryFields Modifier and Type Field Description static intINDEFINITEUsed to specify an animation that repeats indefinitely, until thestop()method is called.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description BooleanPropertyautoReverseProperty()Defines whether thisAnimationreverses direction on alternating cycles.ReadOnlyDoublePropertycurrentRateProperty()Read-only variable to indicate current direction/speed at which theAnimationis being played.ReadOnlyObjectProperty<Duration>currentTimeProperty()Defines theAnimation's play head position.IntegerPropertycycleCountProperty()Defines the number of cycles in this animation.ReadOnlyObjectProperty<Duration>cycleDurationProperty()Read-only variable to indicate the duration of one cycle of thisAnimation: the time it takes to play from time 0 to the end of the Animation (at the defaultrateof 1.0).ObjectProperty<Duration>delayProperty()Delays the start of an animation.ObservableMap<String,Duration>getCuePoints()The cue points can be used to mark important positions of theAnimation.doublegetCurrentRate()Gets the value of the property currentRate.DurationgetCurrentTime()Gets the value of the property currentTime.intgetCycleCount()Gets the value of the property cycleCount.DurationgetCycleDuration()Gets the value of the property cycleDuration.DurationgetDelay()Gets the value of the property delay.EventHandler<ActionEvent>getOnFinished()Gets the value of the property onFinished.doublegetRate()Gets the value of the property rate.Animation.StatusgetStatus()Gets the value of the property status.doublegetTargetFramerate()The target framerate is the maximum framerate at which thisAnimationwill run, in frames per second.DurationgetTotalDuration()Gets the value of the property totalDuration.booleanisAutoReverse()Gets the value of the property autoReverse.voidjumpTo(String cuePoint)Jumps to a predefined position in thisAnimation.voidjumpTo(Duration time)Jumps to a given position in thisAnimation.ObjectProperty<EventHandler<ActionEvent>>onFinishedProperty()The action to be executed at the conclusion of thisAnimation.voidpause()Pauses the animation.voidplay()PlaysAnimationfrom current position in the direction indicated byrate.voidplayFrom(String cuePoint)A convenience method to play thisAnimationfrom a predefined position.voidplayFrom(Duration time)A convenience method to play thisAnimationfrom a specific position.voidplayFromStart()Plays anAnimationfrom initial position in forward direction.DoublePropertyrateProperty()Defines the direction/speed at which theAnimationis expected to be played.voidsetAutoReverse(boolean value)Sets the value of the property autoReverse.voidsetCycleCount(int value)Sets the value of the property cycleCount.protected voidsetCycleDuration(Duration value)Sets the value of the property cycleDuration.voidsetDelay(Duration value)Sets the value of the property delay.voidsetOnFinished(EventHandler<ActionEvent> value)Sets the value of the property onFinished.voidsetRate(double value)Sets the value of the property rate.protected voidsetStatus(Animation.Status value)Sets the value of the property status.ReadOnlyObjectProperty<Animation.Status>statusProperty()The status of theAnimation.voidstop()Stops the animation and resets the play head to its initial position.ReadOnlyObjectProperty<Duration>totalDurationProperty()Read-only variable to indicate the total duration of thisAnimation, including repeats.
 
- 
- 
- 
Property Detail- 
ratepublic final DoubleProperty rateProperty Defines the direction/speed at which theAnimationis expected to be played.The absolute value of rateindicates the speed at which theAnimationis to be played, while the sign ofrateindicates the direction. A positive value ofrateindicates forward play, a negative value indicates backward play and0.0to stop a runningAnimation.Rate 1.0is normal play,2.0is 2 time normal,-1.0is backwards, etc.Inverting the rate of a running Animationwill cause theAnimationto reverse direction in place and play back over the portion of theAnimationthat has already elapsed.- Default value:
- 1.0
- See Also:
- getRate(),- setRate(double)
 
 - 
currentRatepublic final ReadOnlyDoubleProperty currentRateProperty Read-only variable to indicate current direction/speed at which theAnimationis being played.currentRateis not necessary equal torate.currentRateis set to0.0when animation is paused or stopped.currentRatemay also point to different direction during reverse cycles whenautoReverseistrue- Default value:
- 0.0
- See Also:
- getCurrentRate()
 
 - 
cycleDurationpublic final ReadOnlyObjectProperty<Duration> cycleDurationProperty Read-only variable to indicate the duration of one cycle of thisAnimation: the time it takes to play from time 0 to the end of the Animation (at the defaultrateof 1.0).- Default value:
- 0ms
- See Also:
- getCycleDuration(),- setCycleDuration(Duration)
 
 - 
totalDurationpublic final ReadOnlyObjectProperty<Duration> totalDurationProperty Read-only variable to indicate the total duration of thisAnimation, including repeats. AAnimationwith acycleCountofAnimation.INDEFINITEwill have atotalDurationofDuration.INDEFINITE.This is set to cycleDuration * cycleCount. - Default value:
- 0ms
- See Also:
- getTotalDuration()
 
 - 
currentTimepublic final ReadOnlyObjectProperty<Duration> currentTimeProperty Defines theAnimation's play head position.- Default value:
- 0ms
- See Also:
- getCurrentTime()
 
 - 
delaypublic final ObjectProperty<Duration> delayProperty Delays the start of an animation. Cannot be negative. Setting to a negative number will result inIllegalArgumentException.- Default value:
- 0ms
- See Also:
- getDelay(),- setDelay(Duration)
 
 - 
cycleCountpublic final IntegerProperty cycleCountProperty Defines the number of cycles in this animation. ThecycleCountmay beINDEFINITEfor animations that repeat indefinitely, but must otherwise be > 0.It is not possible to change the cycleCountof a runningAnimation. If the value ofcycleCountis changed for a runningAnimation, the animation has to be stopped and started again to pick up the new value.- Default value:
- 1.0
- See Also:
- getCycleCount(),- setCycleCount(int)
 
 - 
autoReversepublic final BooleanProperty autoReverseProperty Defines whether thisAnimationreverses direction on alternating cycles. Iftrue, theAnimationwill proceed forward on the first cycle, then reverses on the second cycle, and so on. Otherwise, animation will loop such that each cycle proceeds forward from the start. It is not possible to change theautoReverseflag of a runningAnimation. If the value ofautoReverseis changed for a runningAnimation, the animation has to be stopped and started again to pick up the new value.- Default value:
- false
- See Also:
- isAutoReverse(),- setAutoReverse(boolean)
 
 - 
statuspublic final ReadOnlyObjectProperty<Animation.Status> statusProperty The status of theAnimation. AnAnimationcan be in one of three states:Animation.Status.STOPPED,Animation.Status.PAUSEDorAnimation.Status.RUNNING.- See Also:
- getStatus(),- setStatus(Animation.Status)
 
 - 
onFinishedpublic final ObjectProperty<EventHandler<ActionEvent>> onFinishedProperty The action to be executed at the conclusion of thisAnimation.- Default value:
- null
- See Also:
- getOnFinished(),- setOnFinished(EventHandler)
 
 
- 
 - 
Field Detail- 
INDEFINITEpublic static final int INDEFINITE Used to specify an animation that repeats indefinitely, until thestop()method is called.- See Also:
- Constant Field Values
 
 
- 
 - 
Constructor Detail- 
Animationprotected Animation(double targetFramerate) The constructor ofAnimation. This constructor allows to define a target framerate.- Parameters:
- targetFramerate- The custom target frame rate for this- Animation
- See Also:
- getTargetFramerate()
 
 - 
Animationprotected Animation() The constructor ofAnimation.
 
- 
 - 
Method Detail- 
setRatepublic final void setRate(double value) Sets the value of the property rate.- Property description:
- Defines the direction/speed at which the Animationis expected to be played.The absolute value of rateindicates the speed at which theAnimationis to be played, while the sign ofrateindicates the direction. A positive value ofrateindicates forward play, a negative value indicates backward play and0.0to stop a runningAnimation.Rate 1.0is normal play,2.0is 2 time normal,-1.0is backwards, etc.Inverting the rate of a running Animationwill cause theAnimationto reverse direction in place and play back over the portion of theAnimationthat has already elapsed.
- Default value:
- 1.0
 
 - 
getRatepublic final double getRate() Gets the value of the property rate.- Property description:
- Defines the direction/speed at which the Animationis expected to be played.The absolute value of rateindicates the speed at which theAnimationis to be played, while the sign ofrateindicates the direction. A positive value ofrateindicates forward play, a negative value indicates backward play and0.0to stop a runningAnimation.Rate 1.0is normal play,2.0is 2 time normal,-1.0is backwards, etc.Inverting the rate of a running Animationwill cause theAnimationto reverse direction in place and play back over the portion of theAnimationthat has already elapsed.
- Default value:
- 1.0
 
 - 
ratePropertypublic final DoubleProperty rateProperty() Defines the direction/speed at which theAnimationis expected to be played.The absolute value of rateindicates the speed at which theAnimationis to be played, while the sign ofrateindicates the direction. A positive value ofrateindicates forward play, a negative value indicates backward play and0.0to stop a runningAnimation.Rate 1.0is normal play,2.0is 2 time normal,-1.0is backwards, etc.Inverting the rate of a running Animationwill cause theAnimationto reverse direction in place and play back over the portion of theAnimationthat has already elapsed.- Default value:
- 1.0
- See Also:
- getRate(),- setRate(double)
 
 - 
getCurrentRatepublic final double getCurrentRate() Gets the value of the property currentRate.- Property description:
- Read-only variable to indicate current direction/speed at which the
 Animationis being played.currentRateis not necessary equal torate.currentRateis set to0.0when animation is paused or stopped.currentRatemay also point to different direction during reverse cycles whenautoReverseistrue
- Default value:
- 0.0
 
 - 
currentRatePropertypublic final ReadOnlyDoubleProperty currentRateProperty() Read-only variable to indicate current direction/speed at which theAnimationis being played.currentRateis not necessary equal torate.currentRateis set to0.0when animation is paused or stopped.currentRatemay also point to different direction during reverse cycles whenautoReverseistrue- Default value:
- 0.0
- See Also:
- getCurrentRate()
 
 - 
setCycleDurationprotected final void setCycleDuration(Duration value) Sets the value of the property cycleDuration.- Property description:
- Read-only variable to indicate the duration of one cycle of this
 Animation: the time it takes to play from time 0 to the end of the Animation (at the defaultrateof 1.0).
- Default value:
- 0ms
 
 - 
getCycleDurationpublic final Duration getCycleDuration() Gets the value of the property cycleDuration.- Property description:
- Read-only variable to indicate the duration of one cycle of this
 Animation: the time it takes to play from time 0 to the end of the Animation (at the defaultrateof 1.0).
- Default value:
- 0ms
 
 - 
cycleDurationPropertypublic final ReadOnlyObjectProperty<Duration> cycleDurationProperty() Read-only variable to indicate the duration of one cycle of thisAnimation: the time it takes to play from time 0 to the end of the Animation (at the defaultrateof 1.0).- Default value:
- 0ms
- See Also:
- getCycleDuration(),- setCycleDuration(Duration)
 
 - 
getTotalDurationpublic final Duration getTotalDuration() Gets the value of the property totalDuration.- Property description:
- Read-only variable to indicate the total duration of this
 Animation, including repeats. AAnimationwith acycleCountofAnimation.INDEFINITEwill have atotalDurationofDuration.INDEFINITE.This is set to cycleDuration * cycleCount. 
- Default value:
- 0ms
 
 - 
totalDurationPropertypublic final ReadOnlyObjectProperty<Duration> totalDurationProperty() Read-only variable to indicate the total duration of thisAnimation, including repeats. AAnimationwith acycleCountofAnimation.INDEFINITEwill have atotalDurationofDuration.INDEFINITE.This is set to cycleDuration * cycleCount. - Default value:
- 0ms
- See Also:
- getTotalDuration()
 
 - 
getCurrentTimepublic final Duration getCurrentTime() Gets the value of the property currentTime.- Property description:
- Defines the Animation's play head position.
- Default value:
- 0ms
 
 - 
currentTimePropertypublic final ReadOnlyObjectProperty<Duration> currentTimeProperty() Defines theAnimation's play head position.- Default value:
- 0ms
- See Also:
- getCurrentTime()
 
 - 
setDelaypublic final void setDelay(Duration value) Sets the value of the property delay.- Property description:
- Delays the start of an animation.
 Cannot be negative. Setting to a negative number will result in IllegalArgumentException.
- Default value:
- 0ms
 
 - 
getDelaypublic final Duration getDelay() Gets the value of the property delay.- Property description:
- Delays the start of an animation.
 Cannot be negative. Setting to a negative number will result in IllegalArgumentException.
- Default value:
- 0ms
 
 - 
delayPropertypublic final ObjectProperty<Duration> delayProperty() Delays the start of an animation. Cannot be negative. Setting to a negative number will result inIllegalArgumentException.- Default value:
- 0ms
- See Also:
- getDelay(),- setDelay(Duration)
 
 - 
setCycleCountpublic final void setCycleCount(int value) Sets the value of the property cycleCount.- Property description:
- Defines the number of cycles in this animation. The cycleCountmay beINDEFINITEfor animations that repeat indefinitely, but must otherwise be > 0.It is not possible to change the cycleCountof a runningAnimation. If the value ofcycleCountis changed for a runningAnimation, the animation has to be stopped and started again to pick up the new value.
- Default value:
- 1.0
 
 - 
getCycleCountpublic final int getCycleCount() Gets the value of the property cycleCount.- Property description:
- Defines the number of cycles in this animation. The cycleCountmay beINDEFINITEfor animations that repeat indefinitely, but must otherwise be > 0.It is not possible to change the cycleCountof a runningAnimation. If the value ofcycleCountis changed for a runningAnimation, the animation has to be stopped and started again to pick up the new value.
- Default value:
- 1.0
 
 - 
cycleCountPropertypublic final IntegerProperty cycleCountProperty() Defines the number of cycles in this animation. ThecycleCountmay beINDEFINITEfor animations that repeat indefinitely, but must otherwise be > 0.It is not possible to change the cycleCountof a runningAnimation. If the value ofcycleCountis changed for a runningAnimation, the animation has to be stopped and started again to pick up the new value.- Default value:
- 1.0
- See Also:
- getCycleCount(),- setCycleCount(int)
 
 - 
setAutoReversepublic final void setAutoReverse(boolean value) Sets the value of the property autoReverse.- Property description:
- Defines whether this
 Animationreverses direction on alternating cycles. Iftrue, theAnimationwill proceed forward on the first cycle, then reverses on the second cycle, and so on. Otherwise, animation will loop such that each cycle proceeds forward from the start. It is not possible to change theautoReverseflag of a runningAnimation. If the value ofautoReverseis changed for a runningAnimation, the animation has to be stopped and started again to pick up the new value.
- Default value:
- false
 
 - 
isAutoReversepublic final boolean isAutoReverse() Gets the value of the property autoReverse.- Property description:
- Defines whether this
 Animationreverses direction on alternating cycles. Iftrue, theAnimationwill proceed forward on the first cycle, then reverses on the second cycle, and so on. Otherwise, animation will loop such that each cycle proceeds forward from the start. It is not possible to change theautoReverseflag of a runningAnimation. If the value ofautoReverseis changed for a runningAnimation, the animation has to be stopped and started again to pick up the new value.
- Default value:
- false
 
 - 
autoReversePropertypublic final BooleanProperty autoReverseProperty() Defines whether thisAnimationreverses direction on alternating cycles. Iftrue, theAnimationwill proceed forward on the first cycle, then reverses on the second cycle, and so on. Otherwise, animation will loop such that each cycle proceeds forward from the start. It is not possible to change theautoReverseflag of a runningAnimation. If the value ofautoReverseis changed for a runningAnimation, the animation has to be stopped and started again to pick up the new value.- Default value:
- false
- See Also:
- isAutoReverse(),- setAutoReverse(boolean)
 
 - 
setStatusprotected final void setStatus(Animation.Status value) Sets the value of the property status.- Property description:
- The status of the Animation. AnAnimationcan be in one of three states:Animation.Status.STOPPED,Animation.Status.PAUSEDorAnimation.Status.RUNNING.
 
 - 
getStatuspublic final Animation.Status getStatus() Gets the value of the property status.- Property description:
- The status of the Animation. AnAnimationcan be in one of three states:Animation.Status.STOPPED,Animation.Status.PAUSEDorAnimation.Status.RUNNING.
 
 - 
statusPropertypublic final ReadOnlyObjectProperty<Animation.Status> statusProperty() The status of theAnimation. AnAnimationcan be in one of three states:Animation.Status.STOPPED,Animation.Status.PAUSEDorAnimation.Status.RUNNING.- See Also:
- getStatus(),- setStatus(Animation.Status)
 
 - 
getTargetFrameratepublic final double getTargetFramerate() The target framerate is the maximum framerate at which thisAnimationwill run, in frames per second. This can be used, for example, to keep particularly complexAnimationsfrom over-consuming system resources. By default, anAnimation's framerate is not explicitly limited, meaning theAnimationwill run at an optimal framerate for the underlying platform.- Returns:
- the target framerate
 
 - 
setOnFinishedpublic final void setOnFinished(EventHandler<ActionEvent> value) Sets the value of the property onFinished.- Property description:
- The action to be executed at the conclusion of this Animation.
- Default value:
- null
 
 - 
getOnFinishedpublic final EventHandler<ActionEvent> getOnFinished() Gets the value of the property onFinished.- Property description:
- The action to be executed at the conclusion of this Animation.
- Default value:
- null
 
 - 
onFinishedPropertypublic final ObjectProperty<EventHandler<ActionEvent>> onFinishedProperty() The action to be executed at the conclusion of thisAnimation.- Default value:
- null
- See Also:
- getOnFinished(),- setOnFinished(EventHandler)
 
 - 
getCuePointspublic final ObservableMap<String,Duration> getCuePoints() The cue points can be used to mark important positions of theAnimation. Once a cue point was defined, it can be used as an argument ofjumpTo()andplayFrom()to move to the associated position quickly.Every Animationhas two predefined cue points"start"and"end", which are set at the start respectively the end of theAnimation. The predefined cuepoints do not appear in the map, attempts to override them have no effect.Another option to define a cue point in a Animationis to set thenameproperty of aKeyFrame.- Returns:
- ObservableMapof cue points
 
 - 
jumpTopublic void jumpTo(Duration time) Jumps to a given position in thisAnimation. If the given time is less thanDuration.ZERO, this method will jump to the start of the animation. If the given time is larger than the duration of thisAnimation, this method will jump to the end.- Parameters:
- time- the new position
- Throws:
- NullPointerException- if- timeis- null
- IllegalArgumentException- if- timeis- Duration.UNKNOWN
- IllegalStateException- if embedded in another animation, such as- SequentialTransitionor- ParallelTransition
 
 - 
jumpTopublic void jumpTo(String cuePoint) Jumps to a predefined position in thisAnimation. This method looks for an entry in cue points and jumps to the associated position, if it finds one.If the cue point is behind the end of this Animation, callingjumpTowill result in a jump to the end. If the cue point has a negativeDurationit will result in a jump to the beginning. If the cue point has a value ofDuration.UNKNOWNcallingjumpTowill have no effect for this cue point.There are two predefined cue points "start"and"end"which are defined to be at the start respectively the end of thisAnimation.- Parameters:
- cuePoint- the name of the cue point
- Throws:
- NullPointerException- if- cuePointis- null
- IllegalStateException- if embedded in another animation, such as- SequentialTransitionor- ParallelTransition
- See Also:
- getCuePoints()
 
 - 
playFrompublic void playFrom(String cuePoint) A convenience method to play thisAnimationfrom a predefined position. The position has to be predefined in cue points. Calling this method is equivalent to
 Note that unlikeanimation.jumpTo(cuePoint); animation.play();playFromStart()calling this method will not change the playing direction of thisAnimation.- Parameters:
- cuePoint- name of the cue point
- Throws:
- NullPointerException- if- cuePointis- null
- IllegalStateException- if embedded in another animation, such as- SequentialTransitionor- ParallelTransition
- See Also:
- getCuePoints()
 
 - 
playFrompublic void playFrom(Duration time) A convenience method to play thisAnimationfrom a specific position. Calling this method is equivalent to
 Note that unlikeanimation.jumpTo(time); animation.play();playFromStart()calling this method will not change the playing direction of thisAnimation.- Parameters:
- time- position where to play from
- Throws:
- NullPointerException- if- timeis- null
- IllegalArgumentException- if- timeis- Duration.UNKNOWN
- IllegalStateException- if embedded in another animation, such as- SequentialTransitionor- ParallelTransition
 
 - 
playpublic void play() PlaysAnimationfrom current position in the direction indicated byrate. If theAnimationis running, it has no effect.When rate> 0 (forward play), if anAnimationis already positioned at the end, the first cycle will not be played, it is considered to have already finished. This also applies to a backward (rate< 0) cycle if anAnimationis positioned at the beginning. However, if theAnimationhascycleCount> 1, following cycle(s) will be played as usual.When the Animationreaches the end, theAnimationis stopped and the play head remains at the end.To play an Animationbackwards from the end:
 animation.setRate(negative rate);
 animation.jumpTo(overall duration of animation);
 animation.play();
 Note: - play()is an asynchronous call, the- Animationmay not start immediately.
 - Throws:
- IllegalStateException- if embedded in another animation, such as- SequentialTransitionor- ParallelTransition
 
 - 
playFromStartpublic void playFromStart() Plays anAnimationfrom initial position in forward direction.It is equivalent to animation.stop();
 animation.setRate = setRate(Math.abs(animation.getRate()));
 animation.jumpTo(Duration.ZERO);
 animation.play();
 Note: - playFromStart()is an asynchronous call,- Animationmay not start immediately.
 - Throws:
- IllegalStateException- if embedded in another animation, such as- SequentialTransitionor- ParallelTransition
 
 - 
stoppublic void stop() Stops the animation and resets the play head to its initial position. If the animation is not currently running, this method has no effect.Note: - stop()is an asynchronous call, the- Animationmay not stop immediately.
 - Throws:
- IllegalStateException- if embedded in another animation, such as- SequentialTransitionor- ParallelTransition
 
 - 
pausepublic void pause() Pauses the animation. If the animation is not currently running, this method has no effect.Note: - pause()is an asynchronous call, the- Animationmay not pause immediately.
 - Throws:
- IllegalStateException- if embedded in another animation, such as- SequentialTransitionor- ParallelTransition
 
 
- 
 
-