Table of contents
1.
Introduction
2.
JavaFX Scaling  
3.
Constructors of Scaling
4.
Properties and Method of JavaFX Scaling
5.
Programs to implement JavaFX Scaling
5.1.
Output
6.
Frequently Asked Questions
6.1.
What does JavaFX's Translatex do?
6.2.
What various transformations does JavaFX support?
6.3.
What do image scaling and translating mean?
7.
Conclusion
Last Updated: Mar 27, 2024
Easy

JavaFX Scaling

Author Ashish Sharma
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

In this article, we will learn about  Scaling, the introduction to JavaFX Scaling, the constructor of JavaFX Scaling, the properties of JavaFX Scaling, and examples of JavaFX Scaling. Scaling transformation is used to alter an object's size. You either increase or decrease the object's dimensions throughout the scaling procedure. To scale an object, multiply its original coordinates by the scaling factor until the desired result is obtained.In JavaFX, the class javafx.scene.transform. Scale is used to represent the scaling transformation.              

JavaFX Scaling  

A type of transformation used to alter an object's size is scaling. It has the ability to either increase or decrease an object's size. By multiplying the item's coordinates by a variable known as the scale factor, the size of the object can be changed. The class javafx.scene.transform in JavaFX. The transition of scaling is represented by scale.

Constructors of Scaling

            Constructor                 Function
Public Scale() establishes a new instance using the default parameters.
Public Scale(double X, double Y, double Z) It will help in creating a new instance of 3D Scale.
Public Scale(double X, double Y) It will help in creating a new instance of 2D Scale.
Public Scale(double X, double Y, double pivotX, double pivotY) 2D new instances will be created with the specified pivot coordinates.
Public Scale(double X,double Y, double Z, double pivotX, double pivotY, double pivotZ) 3D new instances will be created with the specified pivot coordinates.

 

Properties and Method of JavaFX Scaling

                          Method                   Description
Pivot X It is used to indicate the pivot point's x coordinate, and its value is set using the setPivotX(Double value) method.
PivotY It represents the pivot point's y coordinate, around which scaling is carried out.
PivotZ It serves as a representation of the pivot point's z coordinate, around which scaling is carried out.
x It shows how much the object is scaled in relation to the X-axis.
y It shows how much the object is scaled in relation to the Y-axis.
z It shows how much the object is scaled in relation to the Z-axis.

 

Programs to implement JavaFX Scaling

import javafx.application.Application;
import javafx.geometry.Rectangle2D;
import javafx.scene.Group; 
import javafx.scene.Scene; 
import javafx.scene.paint.Color; 
import javafx.scene.shape.Circle;
import javafx.scene.shape.Rectangle;
import javafx.scene.transform.Scale; 
import javafx.stage.Stage; 
         
public class App extends Application {  
   @Override 
   public void start(Stage stage) {      
      //Drawing rectangle1 
      Rectangle rectangle1 = new Rectangle(40,70,220,180);   
      
      //Setting the color of the rectangle 
      rectangle1.setFill(Color.BLUEVIOLET);        
      
      //Setting the stroke width of the circle 
      rectangle1.setStrokeWidth(20);       
      
      //Drawing rectangle2 
      Rectangle rectangle2 = new Rectangle(40,70,220,180);   
      
      //Setting the color of the rectangle 
      rectangle2.setFill(Color.BROWN); 
      
      //Setting the stroke width of the Rectangle 
      rectangle2.setStrokeWidth(50);
      
      //Creating the scale transformation 
      Scale scale = new Scale(); 
      
      //Setting the dimensions for the transformation 
      scale.setX(1.5); 
      scale.setY(1.5); 
      
      //Setting the pivot point for the transformation 
      scale.setPivotX(200); 
      scale.setPivotY(100); 
       
      //Adding the scale transformation to rectangle1 
      rectangle1.getTransforms().addAll(scale); 
         
      //Creating a Group object  
      Group root = new Group(rectangle1, rectangle2); 
         
      //Creating a scene object 
      Scene scene = new Scene(root, 500, 300);  
      
      //Setting title to the Stage 
      stage.setTitle("Coding Ninjas"); 
          
      //Adding scene to the stage 
      stage.setScene(scene); 
         
      //Displaying the contents of the stage 
      stage.show(); 
   }      
   public static void main(String args[]){ 
      launch(args); 
   } 
} 
You can also try this code with Online Java Compiler
Run Code

Output

 

                         Output

Frequently Asked Questions

What does JavaFX's Translatex do?

A translation changes the location of an object on the screen. Adding the translation coordinates (tx, ty) to the original coordinates (X, Y) yields the new coordinates (X', Y'), which is how you move a point in two dimensions.

What various transformations does JavaFX support?

Transformations come in a variety of forms, including translation, scaling up or down, rotation, shearing, and more. Nodes can undergo transformations including rotation, scaling, and translation using JavaFX. The classes that represent all of these modifications are part of the package javafx.

What do image scaling and translating mean?

The scaling transformation modifies the proportions of a shape but not its underlying form. An ellipse can be scaled by 0.5 to get an equivalent shape that is half as broad and half as tall as the original. By a specific amount, the translation transformation moves a shape.

Conclusion

In this article, we have extensively discussed the introduction to JavaFX Scaling, the constructor of JavaFX Scaling, the properties of JavaFX Scaling, and examples of JavaFX Scaling.

After reading about Introduction to JavaFX Scaling, are you not feeling excited to read/explore more articles on the topic of file systems? Don't worry; Coding Ninjas has you covered. If you want to check out articles related to Java refert to these links, Overloading and Overriding static Methods in javaUnderstanding Association, Aggregation, and Composition in Javajava interview questionsMultiple Inheritance in JavaMultilevel Inheritance in Java.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But suppose you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc. In that case, you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Live masterclass