×

JavaFX Translate Transition

In the JavaFX application, in order to generate the translate transition, we have to apply translate transition on any particular shape. It has the ability to translate the shape along all three axis. All methods needed for this purpose are present in the javafx.animation.TranslateTransition class.

Constructor to create Translate Transition:

1. public TranslateTransition():

This empty constructor is used to create translate transition and properties can be set using setters.

2. public TranslateTransition( Duration time ):

This constructor is used to create a translate transition with a specified duration.

3. public TranslateTransition( Duration time, Node n ):

This constructor is used to create a translate transition with a specified duration and node.

Properties and corresponding methods to create Translate Transition:

1. byX

This property is of double type. It is used to represent the factor at which translate X stops and setByX() method is used to set it.

2. byY

This property is of double type. It is used to represent the factor at which translate Y stops and setByY() method is used to set it.

3. byZ

This property is of double type. It is used to represent the factor at which the translate Z stops and setByZ() method is used to set it.

4. fromX

This property is of double type. It is used to represent the start X factor and the setFromX() method is used to set it.

5. fromY

This property is of double type. It is used to represent the start Y factor and the setFromY() method is used to set it.

6. fromZ

This property is of double type. It is used to represent the start Z factor and the setFromZ() method is used to set it.

7. toX

This property is of double type. It is used to represent the stop X factor and the setToX() method is used to set it.

8. toY

This property is of double type. It is used to represent the stop Y factor and the setToY() method is used to set it.

9. toZ

This property is of double type. It is used to represent the stop Z factor and the setToZ() method is used to set it.

JavaFX Animation -Translate Transition

Example:

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 SliderUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    { 
       Circle cir = new Circle(50,100,50);  
           
           cir.setFill(Color.BLUE);  
           cir.setStroke(Color.RED);  
             
           TranslateTransition translate = new TranslateTransition();  
             
           translate.setByX(500);  
             
           translate.setDuration(Duration.millis(7000));  
             
           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);  
    primaryStage.setScene(scene);  
    primaryStage.setTitle("JavaFX Translate Transition example");  
    primaryStage.show();  
      
}  
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the Translate Transition in JavaFX, we have to import all the required libraries such as javafx.animation.TranslateTransition, javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.paint.Color, javafx.scene.shape.Circle, javafx.stage.Stage, javafx.util.Duration.

Then we have created one class named AnimationUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold a translating circle, a Group object is created which is then passed to the Scene class object.

The circle is created with the help of the constructor and size parameters. Then the object of TranslateTransition is created and setters are used to set properties. Then it displays a circle which translates from one place to other.

The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, " JavaFX Translate Transition example”. Also, it displays a circle filled with blue color translating in a given plane.

JavaFX Animation -Translate Transition JavaFX Animation -Translate Transition

Related Topics

JavaFX Drop Shadow

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

4 minutes read.

JavaFX Scatter Chart

In the JavaFX application, in order to create Scatter Chart, the ScatterChart class is used. The Scatter Chart allows us to plot data along the x and y axis of...

4 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 Light Distant

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

4 minutes read.

JavaFX Architecture

JavaFX architecture consists of many built-in components such as JavaFX public API, Scene Graph, Quantum Toolkit, Prism, Glass windowing toolkit, web view, media engines. These components help to develop rich...

3 minutes read.

JavaFX Label

The UI Control Label in a JavaFX is used to display the simple text. To use Label in JavaFX application javafx.scene.control.The label class is used. We can place Labels on...

3 minutes read.

JavaFX Circle

In the JavaFX application, in order to draw a circle, the Circle class is used. The Circle allows us to join any points in the space. All methods needed for...

4 minutes read.

JavaFX Event Filters

In JavaFX, in order to handle the event which are created by any of the mouse action, keyboard action, rotate action, scroll action Event filters are used. The event filters...

3 minutes read.

JavaFX Layouts

Layouts in the JavaFX application are treated as a container for different UI elements such as Button, Label, TextArea, etc. Layouts are used as parent container. The layout is used...

3 minutes read.

JavaFX Scale Transition

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

4 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 Bloom

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

4 minutes read.

JavaFX Translate Transition

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

3 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 Rotate Transition

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

4 minutes read.

JavaFX Event Handling

JavaFX gives way to handle various events in web application, desktop applications and graphical applications. In the JavaFX application, in order to allow user to interact with application various events...

4 minutes read.

JavaFX Image Input

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

4 minutes read.

JavaFX Box

In the JavaFX application, in order to draw a Box, the Box class is used. The Box allows us to form 3D shape having rectangular faces. All methods needed for...

4 minutes read.

JavaFX ID selector

In the JavaFX application, in order to apply various css effect using the id selector, we use the various css classes available in the JavaFX. This is generally used to...

4 minutes read.