×

JavaFX Transformation

In the JavaFX application, in order to apply various transformation effects, we use Transform class. It has the ability to create the transformation on the given object. This transformation changes the form of the given shape by either translation, scaling, rotation, or shearing.  All methods needed for this purpose are present in the javafx.scene.transform package.

Parent class of Transformation: Transform

The class Transfrom in javafx.scene.transform package is the parent class of all transformation classes. It changes the graphics of the object by applying various rules on the object. Also, we can apply multiple transformations to the same object.

Methods of the Transform class:

1. clone()

This method is used to return the deep copy of the transform.

2. createInverse()

This method is used to return the inverse transform of the given transform.

3. determinant()

This method is used to calculate the determinant of the transformation matrix.

4. isIdentity()

This method is used to retrieve the Boolean value for the property of the identity.

5. isType2D()

This method is used to retrieve the Boolean value for the property of the 2D type.

6. transform( double x, double y )

This method is used to transform the given point by a specified parameter.

7. translate( double x, double y)

This method is used to translate the given point by specified parameters.

8. scale( double x, double y)

This method is used to scale the given point by specified parameters.

9. rotate( double angle, double pivotx, double pivoty)

This method is used to rotate the given object around the pivot point by the specified angle.

Various transformations available in the JavaFX:

JavaFX Effect – Transformation

1. Scaling        

This type of transformation is used in the JavaFX to change the actual size of the object. It alters the size of the given node, the javafx.scene.transform.Scale class is used for applying scaling transformation on the object.

2. Rotation     

This type of transformation is used in the JavaFX to rotate the given object. It is used to rotate the given node by specified angle, the javafx.scene.transform.The rotation class is used for applying rotation transformation on the object.

3. Translation

This type of transformation is used in the JavaFX to translate the given object. It is used to change the position of the given node by a specified parameter, the javafx.scene.transform.Translate class is used for applying translation transformation on the object.

4. Multiple Transformation

This type of transformation is used in the JavaFX to apply multiple transformations to the given object. It is used to apply multiple transformations on the same object to show various effects.

5. Shearing

This type of transformation is used in the JavaFX to shear the given object. It is used to change the slope of the given node by a specified parameter, the javafx.scene.transform.Shear class is used for applying shearing transformation on the object.

Steps to apply Transformation Effect on the given node:

  • Importing required libraries:

In order to apply transformation on objects in JavaFX, we have to import all the required libraries such as

  1. javafx.application.Application
  2. javafx.scene.Group
  3. javafx.scene.Scene
  4. javafx.scene.paint.Color
  5. javafx.scene.shape.Rectangle
  6. javafx.scene.transform.Translate
  7. javafx.scene.transform.Scale
  8. javafx.scene.transform.Rotate
  9. javafx.scene.transform.Shear
  10. javafx.stage.Stage
  • Instantiating respective transformation class using the constructor: 

In this step in order to apply a transformation on various objects in javafx, a constructor of either scaling, rotation, translation, or shearing is created. Then object from instantiating is used for the further process.

Example:

Translate translate = new Translate()

Scale scale =  new Scale()

Rotate rotate = new Rotate()

Shear shear = new Shear()

  • Setting the various properties for applying the transformation on the given object:

In order to apply a transformation on various objects in javafx, we have to apply various setters properties on the object of the constructor. This property gives us various transformation.

Example:

scale.setX(double xvalue);  

scale.setY(double yvalue);  

scale.setPivotX(double pivotxvalue);  

scale.setPivotY(double pivotyvalue);  

  • Apply the transformation on the given node:

After setting all the properties on the given node, we can apply the transformation on the given node.

<node-object>.getTransforms().add(<Transform-object>)  


Related Topics

JavaFX Rotation

In the JavaFX application, in order to apply various rotation effects, we use this class. It has the ability to rotate the given object. It rotates the given node along...

3 minutes read.

JavaFX Pie Chart

In the JavaFX application, in order to create Pie Chart, the PieChart class is used. The Pie Chart allows us to plot data along with the sectors of the circle....

3 minutes read.

JavaFX Fill Transition

In the JavaFX application, in order to generate the fill transition, we have to apply fill transition on any particular shape. It has the ability to fill the given shape...

4 minutes read.

JavaFX Color Input

In the JavaFX application, in order to apply various color input effect, we use the ColorInput class. It has the ability to fill the specified shape with a given color...

4 minutes read.

JavaFX Menu

In the JavaFX application, in order to create a menu, menu items, and menu bar, Menu, MenuItem, and MenuBar class is used. The menu allows us to choose options among...

4 minutes read.

JavaFX Shear

In the JavaFX application, in order to apply various shear effect, we use this class. It has the ability to shear the given object along the x or y axis....

3 minutes read.

JavaFX Motion Blur

In the JavaFX application, in order to apply various Motion blur effect, we use Motion Blur class. It has the ability to apply the Motion blur effect on the given...

4 minutes read.

JavaFX Lighting

In the JavaFX application, in order to apply various Lighting effect from a single source, we use this class. It has the ability to lighten a node from a given...

4 minutes read.

JavaFX Slider

In the JavaFX application, in order to slide over a range of data having values, Slider is used. It provides a pane with a Slider to move over a range...

4 minutes read.

JavaFX Light Spot

In the JavaFX application, in order to apply various Light Spot effect from a single source, we use this class. It has the ability to apply light from all the...

4 minutes read.

JavaFX RadioButton

In the JavaFX application, to get the user information in the form of choice from the user, a form is created using radio buttons that allow the user to select...

3 minutes read.

JavaFX Line

In the JavaFX application, in order to draw a line, the Line class is used. The line allows us to join any two points with x and y coordinates in...

3 minutes read.

JavaFX Blend

In the JavaFX application, in order to apply various blend effect, we use Blend class. It has the ability to blend the colors of the shape. All methods needed for...

4 minutes read.

JavaFX Reflection

In the JavaFX application, in order to apply various reflection effect, we use this class. It has the ability to create the reflection of the given object. This effect adds...

4 minutes read.

JavaFX Color

In the JavaFX application, in order to draw any shape, we are using classes present in the javafx.scene.shape package. We can fill the colors in these shapes using the setFill()...

6 minutes read.

JavaFX GridPane

In the JavaFX application, in order to set Grid Pane as a layout, the GridPane class is used. The GridPane layout allows us to arrange the components in the form...

4 minutes read.

JavaFX Gradient Color

In the JavaFX application, in order to draw any shape, we are using classes present in the javafx.scene.shape package. We can fill the gradient colors in these shapes using the...

7 minutes read.

JavaFX CheckBox

In the JavaFX application, to get the user information in the form of choices from the user, a form is created using checkboxes that allow the user to select two...

4 minutes read.

JavaFX Tutorial

Introduction of JavaFX: The most popular applications called Rich Internet Application are build using the JavaFX. This application can run across many platforms. Various devices such as mobile, computers, and tablets...

4 minutes read.

JavaFX Gaussian Blur

In the JavaFX application, in order to apply various Gaussian blur effect, we use GaussianBlur class. It has the ability to apply blur effect on the given object. All methods...

4 minutes read.