JavaFX Tutorial Index

JavaFX Tutorial JavaFX Installation JavaFX Application Structure JavaFX Architecture

JavaFX Applications Charts

JavaFX Bar Chart JavaFX Bubble Chart JavaFX Pie Chart JavaFX Scatter Chart JavaFX Area Chart JavaFX Line Chart

JavaFX 2D Shapes

JavaFX Arc JavaFX Circle JavaFX Ellipse JavaFX Line JavaFX Polygon JavaFX Rectangle JavaFX Color JavaFX Gradient Color

JavaFX 3D Shapes

JavaFX Box JavaFX Cylinder JavaFX Sphere

JavaFX Animations

JavaFX Rotate Transition JavaFX Translate Transition JavaFX Fade Transition JavaFX Fill Transition JavaFX Parallel Transition JavaFX Path Transition JavaFX Pause Transition JavaFX Scale Transition JavaFX Sequential Transition JavaFX Stroke Transition

JavaFX CSS

JavaFX ID Selector JavaFX Inline Styles JavaFX Selectors

JavaFX Effect

JavaFX Blend JavaFX Bloom JavaFX Color Adjust JavaFX Color Input JavaFX Drop Shadow JavaFX Gaussian Blur JavaFX Glow JavaFX Image Input JavaFX Inner Shadow JavaFX Light Distant JavaFX Light Point JavaFX Light Spot JavaFX Lighting JavaFX Motion Blur JavaFX Reflection JavaFX Shadow

JavaFX Layouts

JavaFX Layouts JavaFX BorderPane JavaFX GridPane JavaFX StackPane JavaFX HBox JavaFX TilePane

JavaFX Event Handling

JavaFX Event Handling JavaFX Event Filters JavaFX Convenience Methods

JavaFX Transformation

JavaFX Transformation JavaFX Scaling JavaFX Rotation JavaFX Translation JavaFX Shear

JavaFX UI

JavaFX Menu JavaFX Button JavaFX Button Styling JavaFX CheckBox JavaFX File Chooser JavaFX HyperLink JavaFX Label JavaFX UI Controls JavaFX PasswordField JavaFX ProgressBar JavaFX RadioButton JavaFX ScrollBar JavaFX Slider JavaFX TextField

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>)