JavaFX Scaling

Scaling is a kind of transformation which is used to change the size of the object. It can either expand the size or compress the size of the object. The size can be altered by multiplying the coordinates of the object by a factor which is called scale factor. In JavaFX, the class javafx.scene.transform.Scale represents the scaling transformation.

In the following image, the scaling transformation is applied to the cube to expend its size.


JavaFX Scaling

Properties

The properties of the class are described in the following table.

PropertyDescriptionSetter Methods
pivotXIt is a double type property. It represents the x coordinate of the pivot point about which the scaling is done.setPivotX(double value)
pivotYIt is a double type property. It represents the y coordinate of the pivot point about which the scaling is done.setPivotY(double value)
pivotZIt is a double type property. It represents the z coordinate of the pivot point about which the scaling is done.setPivotZ(double value)
xIt is a double type property. It represents the factor by which the object is scaled along the X axis.setX(double value)
yIt is a double type property. It represents the factor by which the object is scaled along the Y axis.setY(double value)
zIt is a double type property. It represents the factor by which the object is scaled along the Z axis.setZ(double value)

Constructors

The class contains five constructors described below.

  1. public Scale() : creates the new instance with the default parameters.
  2. public Scale(double X, double Y) : creates the new instance of 2D Scale.
  3. public Scale(double X, double Y, double Z) : creates the new instance of 3D scale.
  4. public Scale(double X, double Y, double pivotX, double pivotY) : creates the new instance of the 2D scale with the specified pivot coordinates.
  5. public Scale(double X, double Y, double Z, double pivotX, double pivotY, double pivotZ) : creates the new instance of the 3D Scale with the specified pivot coordinates.

Example:

The following example illustrates the implementation of Scaling transformation. Here, we have created two circles with the same dimensions and same color. The scaling transform is applied to the 2nd circle to get it scaled by the factor 1.5 in X-Y direction both. After applying the scaling transform to the 2nd circle, it gets 1.5 of the first circle.


JavaFX Scaling
Next TopicJavaFX Shearing




Latest Courses