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