Class KeyFrame
- javafx.animation.KeyFrame
public final class KeyFrame extends Object
Timeline. The developer controls the interpolation of a set of variables for the interval between successive key frames by providing a target value and an Interpolator associated with each variable. The variables are interpolated such that they will reach their target value at the specified time. An onFinished function is invoked on each KeyFrame if one is provided. A KeyFrame can optionally have a name, which will result in a cuepoint that is automatically added to the Timeline.
Since:
JavaFX 2.0
See Also:
-
Constructor Summary
Constructors Constructor and Description KeyFrame(Duration time, EventHandler<ActionEvent> onFinished, KeyValue... values)Constructor ofKeyFrameKeyFrame(Duration time, KeyValue... values)Constructor ofKeyFrameKeyFrame(Duration time, String name, EventHandler<ActionEvent> onFinished, Collection<KeyValue> values)Constructor ofKeyFrameKeyFrame(Duration time, String name, EventHandler<ActionEvent> onFinished, KeyValue... values)Constructor ofKeyFrameKeyFrame(Duration time, String name, KeyValue... values)Constructor ofKeyFrame
-
Method Summary
All MethodsInstance MethodsConcrete Methods Modifier and Type Method and Description booleanequals(Object obj)Indicates whether some other object is "equal to" this one.StringgetName()Returns thenameof thisKeyFrame.EventHandler<ActionEvent>getOnFinished()Returns theonFinishedevent handler of thisKeyFrame.DurationgetTime()Returns the time offset of thisKeyFrame.Set<KeyValue>getValues()Returns an immutableSetofKeyValueinstances.inthashCode()Returns a hash code for thisKeyFrameobject.StringtoString()Returns a string representation of thisKeyFrameobject.
-
Constructor Detail
-
KeyFrame
public KeyFrame(Duration time, String name, EventHandler<ActionEvent> onFinished, Collection<KeyValue> values)Constructor ofKeyFrameIf a passed in
KeyValueisnullor a duplicate, it will be ignored.Parameters:
time- thetimeThrows:
NullPointerException- iftimeis null
-
KeyFrame
public KeyFrame(Duration time, String name, EventHandler<ActionEvent> onFinished, KeyValue... values)Constructor ofKeyFrameIf a passed in
KeyValueisnullor a duplicate, it will be ignored.Parameters:
time- thetimeThrows:
NullPointerException- iftimeis null
-
KeyFrame
public KeyFrame(Duration time, EventHandler<ActionEvent> onFinished, KeyValue... values)Constructor ofKeyFrameParameters:
time- thetimeThrows:
NullPointerException- iftimeis null
-
KeyFrame
public KeyFrame(Duration time, String name, KeyValue... values)Constructor ofKeyFrameParameters:
time- thetimeThrows:
NullPointerException- iftimeis null
-
KeyFrame
public KeyFrame(Duration time, KeyValue... values)Constructor ofKeyFrameParameters:
time- thetimeThrows:
NullPointerException- iftimeis null
-
-
Method Detail
-
getTime
public Duration getTime()
Returns the time offset of thisKeyFrame. The returnedDurationdefines the time offset within a single cycle of aTimelineat which theKeyValueswill be set and at which theonFinishedfunction variable will be called.The
timeof aKeyFramehas to be greater than or equal toDuration.ZEROand it cannot beDuration.UNKNOWN. Note: While the unit oftimeis a millisecond, the granularity depends on the underlying operating system and will in general be larger. For example animations on desktop systems usually run with a maximum of 60fps which gives a granularity of ~17 ms.
-
getValues
public Set<KeyValue> getValues()
Returns an immutableSetofKeyValueinstances. AKeyValuedefines a target and the desired value that should be interpolated at the specified time of thisKeyFrame.
-
getOnFinished
public EventHandler<ActionEvent> getOnFinished()
Returns theonFinishedevent handler of thisKeyFrame. TheonFinishedevent handler is a function that is called when the elapsed time on a cycle passes the specified time of thisKeyFrame. TheonFinishedfunction variable will be called if the elapsed time passes the indicated value, even if it never equaled the time value exactly.
-
getName
public String getName()
-
toString
public String toString()
Returns a string representation of thisKeyFrameobject.
-
hashCode
public int hashCode()
Returns a hash code for thisKeyFrameobject.
-
equals
public boolean equals(Object obj)
Indicates whether some other object is "equal to" this one. TwoKeyFramesare considered equal, if theirtime,onFinished, andvaluesare equal.
-
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.