×

JavaFX Pause Transition

In the JavaFX application, in order to generate the pause transition, we have to apply pause transition on any particular shape. It has the ability to take a particular pause as mentioned between specified animations. All methods needed for this purpose are present in the javafx.animation.PauseTransition class.

Properties and corresponding methods to create Pause Transition:

duration:

This property is of the object type. It is used to represent the duration of the transition and the setDuration() method is used to set it.

Constructors to create Pause Transition:

1. public PauseTransition()

This empty constructor is used to create a pause transition.

2. public PauseTransition(Duration duration)

This constructor is used to create pause transition with specified duration.

JavaFX Animation - Pause 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 newrect = new Rectangle(120,120,100,100);     
    newrect.setStroke(Color.BLUE);  
    newrect.setFill(Color.RED);  
    newrect.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 newseq = new SequentialTransition (newrect,scale, pause, fade);  
           
         newseq.play();  
       
        Group root = new Group();  
        root.getChildren().addAll(newrect);  
         Scene scene = new Scene(root,500,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Pause Transition example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the Pause Transition in JavaFX, we have to import all the required libraries such as javafx.animation.FadeTransition, javafx.animation.PauseTransition , javafx.animation.ScaleTransition,  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 multiple animation with pause, 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 pause Transition object is created and using setters various properties are set. Then it will show a scaling rectangle and take a pause and then fade 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 Pause Transition Example”. Also, it displays a rectangle scaling first then takes a pause, and then shows a faded rectangle.

JavaFX Animation - Pause Transition JavaFX Animation - Pause Transition

JavaFX Animation -Pause Transition between fade and translate transition:

Example:

import javafx.animation.FadeTransition;
import javafx.animation.PauseTransition;
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 newrect = new Rectangle(120,120,100,100);     
    newrect.setStroke(Color.BLUE);  
    newrect.setFill(Color.RED);  
    newrect.setStrokeWidth(20);  
          
           Duration dur1 = Duration.millis(1000);  
           Duration dur2 = Duration.millis(1000);  
         
             
           PauseTransition pause = new PauseTransition(Duration.millis(1000));  
           
    FadeTransition fade = new FadeTransition(dur2);  
         fade.setFromValue(1.0f);  
         fade.setToValue(0.3f);  
         fade.setCycleCount(2);  
         fade.setAutoReverse(true);  
         
         TranslateTransition translate = new TranslateTransition(dur1);  
         translate.setByX(200);  
         
         translate.setDuration(Duration.millis(3000));  
           
         translate.setCycleCount(200);  
           
         translate.setAutoReverse(true);  




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

Output:

In order to create the Pause Transition between animations in JavaFX, we have to import all the required libraries such as javafx.animation.FadeTransition, javafx.animation.PauseTransition , javafx.animation.TranslateTransition,  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 fade and translate animation with pause, 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 pause Transition object is created and using setters various properties are set. Then it will show fading rectangle and take pause and then show translated 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 Pause Transition Example”. Also, it displays a rectangle fading first then taking a pause, and then showing translated rectangle.

JavaFX Animation - Pause Transition JavaFX Animation - Pause Transition

Related Topics

JavaFX Inner Shadow

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

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

The button is one of the UI control present in the JavaFX. The javafx.scene.control.Button class is used for creating a button in javafx example. It is also possible to create...

5 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 Gradient Color

In the JavaFX application, in order to draw any shape, we are using classes present in the javafx.scene.shape package. We can fill the gradient colors in these shapes using the...

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

In the JavaFX application, in order to access and use webpages, hyperlinks are used. In HTML anchor tags are used in the same way in JavaFX hyperlinks are used. To...

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

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

3 minutes read.

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

In the JavaFX application, in order to set Border Pane as a layout, the BorderPane class is used. The BorderPane layout allows us to arrange the components in the left,...

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 Shadow

In the JavaFX application, in order to apply various Shadow effect from a single source, we use this class. It has the ability to create the shadow of the given...

3 minutes read.

JavaFX Inline Styles

In the JavaFX application, in order to apply various Inline css effect we will use the various css classes available in the JavaFX. It is used to apply the various...

4 minutes read.

JavaFX Lighting

In the JavaFX application, in order to apply various Lighting effect from a single source, we use this class. It has the ability to lighten a node from a given...

4 minutes read.

JavaFX Motion Blur

In the JavaFX application, in order to apply various Motion blur effect, we use Motion Blur class. It has the ability to apply the Motion blur effect on the given...

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

In the JavaFX application, in order to draw an Ellipse, the Ellipse class is used. The Ellipse allows us to join any points in the space to draw the unique...

7 minutes read.