Introduction
JavaFX is a platform used in the creation and development of desktop applications and rich web applications so that they run across a wide variety of devices. JavaFX has support for Microsoft Windows, macOS, and Linux. Mobile devices running on iOS and Android also support JavaFX. JavaFX comes with a wide variety of features which includes typeface, Java libraries, JavaFX Script, high availability, transformations it allows, etc. which makes it very convenient to use. In this blog, we will learn about one such in-built transformation available, that is, JavaFX Rotation.
JavaFX Rotation
When we say Rotation, it means to turn the object from its origin. JavaFX Rotation is used for the same, that is, to rotate any object by a certain angle present in the graph screen. The class used to represent translation is javafx.scene.transform.Rotate in which javafx.scene.transform is the parent class. In order to apply various rotation effects, we use this class. It has the ability to rotate any object by rotating its nodes. This rotation is done along a pivot point with a specified angle.
You can refer to the images below for a better understanding.

Before JavaFX Rotation

After JavaFX Rotation
From the images, we could imagine that how actually performing JavaFX rotation would look like. The image has been rotated around a pivot point.
The various properties used to create rotate transformations are mentioned below in the table.
| PROPERTIES | DESCRIPTION | METHOD |
| axis | An axis is an object-type property used to represent the axis of the rotation of the nodes and consequently the object. | setAxis(Point3D value) |
| angle | An angle is a double-type property used to represent the angle by which the object has to be rotated. | setAngle(Double value) |
| pivotX | The pivotX is a double-type property used for representation of the x-coordinate of the pivot point. | setPivotX(Double value) |
| pivotY | The pivotY is a double-type property used for representation of the y-coordinate of the pivot point. | setPivotY(Double value) |
| pivotZ | The pivotZ is a double-type property used for representation of the z-coordinate of the pivot point. | setPivotZ(Double value) |
Types of Constructors
The javafx.scene.transform.Rotate class contains six types of constructors. To learn about them, follow these descriptions below.
-
public Rotate()
This constructor creates the rotate transform using the default parameters.
-
public Rotate(double angle)
This constructor creates the rotate transform using the specified angle which is measured in degrees. The pivot points are set to (0,0) by default since the rotation is being done in 2D.
-
public Rotate(double angle, Point3D axis)
This constructor creates the 3D rotate transform using the specified transform, that is, the angle of rotation and the axis around which the rotation has to be performed is given. The pivot points are set to (0,0,0) by default since the rotation is being done in 3D.
-
public Rotate(double angle, double pivotX, double pivotY)
This constructor uses three parameters to create the rotate transform using the specified angle and the 2D pivot coordinate (x,y) around which the rotation has to be performed.
-
public Rotate(double angle, double pivotX, double pivotY, double pivotZ)
This constructor uses four parameters to create the rotate transform using the specified angle and 3D pivot coordinate (x,y,z) around which the rotation has to be performed.
-
public Rotate(double angle, double pivotX, double pivotY, double pivotZ,Point3D Axis)
This constructor uses five parameters to create a 3D Rotate transform with the specified angle, 3D pivot coordinate (x,y,z) and the axis around which the rotation has to be performed.
Implementation in Java
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Pane;
import javafx.scene.transform.Rotate;
import javafx.stage.Stage;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
//function to implement rotate transformation.
public class RotateTransformationExample extends Application
{
public static void main(String[] args)
{
launch(args);
}
//Function to create a figure.
public void start(Stage primaryStage)
{
ImageView imageViewOriginal = createImageView();
ImageView imageViewTranslated = createImageView();
Rotate rotateTransform = new Rotate();
rotateTransform.setAngle(45);
rotateTransform.setPivotX(0);
rotateTransform.setPivotY(0);
imageViewTranslated.getTransforms().add(rotateTransform);
Pane pane = new Pane();
pane.getChildren().add(imageViewTranslated);
pane.getChildren().add(imageViewOriginal);
Scene scene = new Scene(pane, 1024, 800, true);
primaryStage.setScene(scene);
primaryStage.setTitle("2D Example");
primaryStage.show();
}
//Function to assign memory to the image.
private ImageView createImageView()
{
FileInputStream input = null;
try {
input = new FileInputStream("assets/media/abstract-5719221_640.jpg");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Image image = new Image(input);
ImageView imageView = new ImageView(image);
return imageView;
}
}
On executing the implementation above, we get the output image as:





