×

JavaFX Sequential Transition

In the JavaFX application, in order to generate the sequential transition, we have to apply sequential transition on any particular shape. It has the ability to execute multiple transactions sequentially one after the another after a specific pause. All methods needed for this purpose are present in the javafx.animation.SequentialTransition class.

JavaFX Animation - Sequential Transition as a combination of Scale and Fade transition

Example:

import javafx.animation.FadeTransition;
import javafx.animation.PauseTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.SequentialTransition;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;


public class AnimationUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
    
    Rectangle newcir = new Rectangle(140,140,100,100);     
    newcir.setStroke(Color.BLUE);  
    newcir.setFill(Color.RED);  
    newcir.setStrokeWidth(20);  
          
           Duration dur1 = Duration.millis(1000);  
           Duration dur2 = Duration.millis(5000);  
         
             
           PauseTransition pause = new PauseTransition(Duration.millis(5000));  
           
    FadeTransition fade = new FadeTransition(dur2);  
         fade.setFromValue(1.0f);  
         fade.setToValue(0.3f);  
         fade.setCycleCount(2);  
         fade.setAutoReverse(true);  
         
         ScaleTransition scale = new ScaleTransition(dur1);  
         scale.setByX(1.5f);
         scale.setByY(1.5f);
         scale.setAutoReverse(true);




           
         SequentialTransition seqT = new SequentialTransition (newcir,scale, pause, fade);  
           
         seqT.play();  
       
        Group root = new Group();  
        root.getChildren().addAll(newcir);  
         Scene scene = new Scene(root,500,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Sequential Transition example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the sequential Transition in JavaFX, we have to import all the required libraries such as javafx.animation.ScaleTransition, javafx.animation.SequentialTransition, javafx.animation.FadeTransition, javafx.animation.PauseTransition, javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.paint.Color, javafx.scene.shape.Rectangle, 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 sequential transition on the given rectangle , a Group object is created which is then passed to the Scene class object.

The Rectangle is created with the help of the constructor and the size parameter and red color to be filled are passed in it. A Sequential Transition object is created and using setters various properties are set. Then it will show sequential transitions on the rectangle.

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 Animation - Sequential Transition Example”. Also, it displays a rectangle filled with red color and blue stroke increasing shape and then after pause rectangle gets faded.

JavaFX Animation - Sequential Transition JavaFX Animation - Sequential Transition

JavaFX Animation - Sequential Transition as a combination of Scale and Translate transition

Example:

import javafx.animation.PauseTransition;
import javafx.animation.ScaleTransition;
import javafx.animation.SequentialTransition;
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.Rectangle;
import javafx.stage.Stage;
import javafx.util.Duration;


public class AnimationUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
   
    
    Rectangle newcir = new Rectangle(140,140,100,100);     
    newcir.setStroke(Color.BLUE);  
    newcir.setFill(Color.RED);  
    newcir.setStrokeWidth(20);  
          
       Duration dur1 = Duration.millis(1000);  
         
             
           PauseTransition pause = new PauseTransition(Duration.millis(5000));  
           
           TranslateTransition translate = new TranslateTransition(dur1);  
           translate.setByX(500);  
           
           translate.setDuration(Duration.millis(7000));  
             
           translate.setCycleCount(500);  
             
           translate.setAutoReverse(true);  
             


         
         ScaleTransition scale = new ScaleTransition(dur1);  
         scale.setByX(1.5f);
         scale.setByY(1.5f);
         scale.setAutoReverse(true);




           
         SequentialTransition seqT = new SequentialTransition (newcir,scale, pause, translate);  
           
         seqT.play();  
       
        Group root = new Group();  
        root.getChildren().addAll(newcir);  
         Scene scene = new Scene(root,500,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Sequential Transition example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the sequential Transition in JavaFX, we have to import all the required libraries such as javafx.animation.ScaleTransition, javafx.animation.SequentialTransition, javafx.animation.TranslateTransition, javafx.animation.PauseTransition, javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.paint.Color, javafx.scene.shape.Rectangle, 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 sequential transition on the given rectangle , a Group object is created which is then passed to the Scene class object.

The Rectangle is created with the help of the constructor and the size parameter and red color to be filled in it with blue stroke. A Sequential Transition object is created and using setters various properties are set. Then it will show sequential transitions on the rectangle which is a combination of scale and translate transition.

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 Sequential Transition example”. Also, it displays a rectangle filled with red color and blue stroke increasing shape and then after pause rectangle translates from one place to another.

JavaFX Animation - Sequential Transition JavaFX Animation - Sequential Transition

Related Topics

JavaFX Polygon

In the JavaFX application, in order to draw a polygon, the Polygon class is used. The Polygon allows us to join any number of points in the space. All methods...

4 minutes read.

JavaFX Slider

In the JavaFX application, in order to slide over a range of data having values, Slider is used. It provides a pane with a Slider to move over a range...

4 minutes read.

JavaFX Pie Chart

In the JavaFX application, in order to create Pie Chart, the PieChart class is used. The Pie Chart allows us to plot data along with the sectors of the circle....

3 minutes read.

JavaFX Rotation

In the JavaFX application, in order to apply various rotation effects, we use this class. It has the ability to rotate the given object. It rotates the given node along...

3 minutes read.

JavaFX Area Chart

In the JavaFX application, in order to create Area Chart, the AreaChart class is used. The Area Chart allows us to plot data along the XY plane. All methods needed...

3 minutes read.

JavaFX Fade Transition

In the JavaFX application, in order to generate the fade transition, we have to apply fade transition on any particular shape. It has the ability to show the fading colors...

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.

JavaFX Reflection

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

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

In the JavaFX application, in order to draw a Cylinder, the Cylinder class is used. The Cylinder allows us to form a 3D shape having rectangular faces and a straight...

4 minutes read.

JavaFX UI Controls

We can make an advanced graphical user interface (GUI) for the JavaFX application using UI Controls and layouts. Various UI elements can be used b the programmer in their application...

3 minutes read.

JavaFX Bar Chart

In the JavaFX application, in order to create Bar Chart, the BarChart class is used. The Bar Chart allows us to plot data along different bars to show the scales...

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

In the JavaFX application, in order to apply various color adjust effect, we use ColorAdjust class. It has the ability to apply various color adjust effect such as hue, saturation,...

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

3 minutes read.

JavaFX StackPane

In the JavaFX application, in order to set Stack Pane as a layout, the StackPane class is used. The StackPane layout allows us to arrange the components in the stack...

4 minutes read.

JavaFX File Chooser

In the JavaFX application, in order to open or save the file, FileChooser is used. It allows user to choose the file from system location and save it in a...

4 minutes read.

JavaFX Glow

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

4 minutes read.