Table of contents
1.
Introduction
2.
JavaFX Scale Transition
2.1.
Properties
2.2.
Constructors
2.3.
Example
3.
Frequently Asked Questions
3.1.
What is the main purpose of JavaFX?
3.2.
What are the various features of JavaFX?
3.3.
What are the life cycle methods of JavaFX?
4.
Conclusion
Last Updated: Mar 27, 2024

JavaFX Scale Transition

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

Introduction

To generate the scale transition in the JavaFX application, we must apply scale transition to any specific shape. It is capable of scaling the form along all three axes. The javafx.animation.ScaleTransition class contains all the necessary methods for this purpose.

Let us understand this with the help of examples.

JavaFX Scale Transition

This transition animates the scaling of the node by the provided factor during the specified period in any or all of the three directions X, Y, and Z.

ScaleTransition in JavaFX is represented by the class javafx.animation.

ScaleTransition. To produce an acceptable scale transition, we must instantiate this class.

Properties

The following table describes the class's attributes and associated setter methods.

An image of a table containing various properties of javaFX class.

Constructors

The class contains three constructors.

  1. public TranslateTransition(): This generates a new instance of TranslateTransition with the default parameters.
     
  2. public TranslateTransition(Duration duration): creates a new instance of TranslateTransition for the duration provided.
     
  3. public TranslateTransition(Duration duration, Node node): returns a new instance of Translate Transition with the given duration and node.

Example

In the following example, we construct a circle that translates 500 degrees in the X-direction.

import javafx.animation.TranslateTransition;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Circle;
import javafx.stage.Stage;
import javafx.util.Duration;
public
class NewFXMain extends Application
{
    @Override public void start(Stage primaryStage) throws Exception
    {
        Circle cir = new Circle(50, 100, 50);


        cir.setFill(Color.RED);
        cir.setStroke(Color.BLACK);


        TranslateTransition translate = new TranslateTransition();


        translate.setByX(500);
        translate.setDuration(Duration.millis(1000));
        translate.setCycleCount(500);
        translate.setAutoReverse(true);
        translate.setNode(cir);
        translate.play();


        Group root = new Group();
        root.getChildren().addAll(cir);
        Scene scene = new Scene(root, 500, 200, Color.WHEAT);
        primaryStage.setScene(scene);
        primaryStage.setTitle("JavaFX Scale Transition example");
        primaryStage.show();
    }
public
    static void main(String[] args)
    {
        launch(args);
    }
}
You can also try this code with Online Java Compiler
Run Code

Output:

It can be seen through the images below that the circle translates in the X direction from left to right.

An image showing transition of a circle from left to right, done using javaFX scale transition.

An image showing transition of a circle from left to right, done using javaFX scale transition.

An image showing transition of a circle from left to right, done using javaFX scale transition.

Frequently Asked Questions

What is the main purpose of JavaFX?

JavaFX is a collection of graphics and media packages that allow developers to create, test, debug, and deploy rich client applications that work reliably across several platforms.

What are the various features of JavaFX?

Scene Builder produces FXML markup that may be imported into an IDE. JavaFX applications may be embedded in web pages. Web View embeds web pages using WebKitHTML technology. JavaFX has built-in components that are not affected by the operating system.

What are the life cycle methods of JavaFX?

start() is the entry point function for writing JavaFX graphics code. stop() is an empty method that may be customized with logic to stop the program. init() is an empty method that may be overridden, but it cannot build a stage or a scene.

Conclusion

In this article, we have extensively discussed the JavaFX Scale Transition, its properties, and its constructors. We learned to create a transition with the help of an example. 

We hope that this blog has helped you enhance your knowledge of Java and JavaFX and if you would like to learn more about java, check out our articles, java archivesJavaFX - Coding Ninjas Coding Ninjas Studio

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 if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc., 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!

An image that displays a thankyou message from coding ninjas.

Live masterclass