JavaFX Translation

Translation can be defined as change in the position of an object on the screen. The position of an object gets changed by moving it along the X-Y direction. In JavaFX, the class javafx.scene.transform.Translate represents the Translate transform. We need to instantiate this class in order to translate the object.

The following image translates the circle from one position to the another position. The centre coordinate of the circle P(x,y) gets converted to P(x1,y1). The X coordinate is changed by the factor Tx while the Y coordinate is changed by the factor Ty.


JavaFX Translation

Properties

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

PropertyDescriptionSetter Methods
XIt is a double type property. It represents the distance by which the object is translated in X Direction.setX(double value)
YIt is a double type property. It represents the distance by which the object is translated in Y direction.setY(double value)
ZIt is a double type property. It represents the distance by which the object is translated in Z direction.setZ(double value)

Constructors

The class contains three constructors

  1. public Translate() : creates the new instance of the Translate class with the default parameters.
  2. public Translate(double X, double Y) : creates the new instance with the specified (X, Y) coordinate.
  3. public Translate(double X, double Y, double Z) : creates the new instance with the specified (x,y,z) coordinate.

Example:

The following example illustrates the Translation transform on the rectangle. Here, we have created two rectangles with the same coordinates. The first rectangle is filled with the Red color while the second rectangle is filled with the green color. The green rectangle is moved to the different place by setting the properties of the translate object to the appropriate values.


JavaFX Translation
Next TopicJavaFX Rotation




Latest Courses