JavaFX Translate Transition

It translates the node from one position to the another position over the specified duration. Transition is done by keep updating the translateX and translateY properties of the node at the regular intervals.

The speed of the transition depends upon the number of cycles, transition will have in the specified duration.

In JavaFX, the TranslateTransition is represented by the class javafx.animation.TranslateTransition. We need to instantiate this class in order to apply an appropriate Translate Transition on an object.

Properties

The properties of the class along with the setter methods are described in the following table.

PropertyDescriptionSetter Method
byXThis is a double type property. It represents the incremented X-coordinate value at which, the translation stops.setByX(double value)
byYThis is a double type property. It represents the incremented Y-coordinate value at which, the translation stops.setByY(double value)
byZThis is a double type property. It represents the incremented Z-coordinate value at which, the translation stops.setByZ(double value)
durationThis is an object type property of the class Duration . It represents the duration of Translate transition.setDuration(Duration value)
fromXThis is a double type property. It represents the X coordinate value from which the translation starts.setFromX(double value)
fromYThis is a double type property. It represents the Y coordinate value from which the translation starts. This is a double type property. It represents the X coordinate value from which the translation starts.setFromY(double value)
fromZThis is a double type property. It represents the Z coordinate value from which the translation starts.setFromZ(double value)
nodeThis is an object type property of the class Node. It represents the node onto which, the scale transition is applied.setNode(Node node)
toXThis is a double type property. It represents the stop X coordinate value of the translate transition.setToX(double value)
toYThis is a double type property. It represents the stop Y coordinate value of the translate transition.setToY(double value)
toZThis is a double type property. It represents the stop Z coordinate value of the scale transition.setToZ(double value)

Constructors

There are three constructors in the class.

  1. public TranslateTransition() : creates the new instance of TranslateTransition with the default parameters.
  2. public TranslateTransition(Duration duration) : creates the new instance of TranslateTransition with the specified duration.
  3. public TranslateTransition(Duration duration, Node node) : creates the new instance of Translate Transition with the specified duration and node.

Example:

In the following example, we have made a circle translating itself by 400 in the X direction.

Output:


JavaFX Translate Transition




Latest Courses