×

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 with the given color. All methods needed for this purpose are present in the javafx.animation.FillTransition class.

Properties and corresponding methods to create Fill Transition:

1. shape

This property is of object type. It is used to represent the shape that is to be filled and the setShape() method is used to set it.

2. fromValue

This property is of double type. It is used to represent the start color and the setFromValue() method is used to set it.

3. toValue

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

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

JavaFX Animation - Fill Transition

Example:

import javafx.animation.FillTransition;
import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.paint.Color;
import javafx.scene.shape.Polygon;
import javafx.stage.Stage;
import javafx.util.Duration;


public class AnimationUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
   
    Polygon newpoly = new Polygon();  
 
    newpoly.getPoints().addAll(new Double[] {220.0,270.0,170.0,220.0,170.0,120.0,220.0,70.0,270.0,120.0,270.0,220.0});  
          
    newpoly.setStroke(Color.BLACK);  
          
        FillTransition newfill = new FillTransition();  
          
        newfill.setAutoReverse(true);  
          
        newfill.setCycleCount(50);  
          
        newfill.setDuration(Duration.millis(1000));  
          
        newfill.setFromValue(Color.RED);  
          
        newfill.setToValue(Color.WHITE);  
          
        newfill.setShape(newpoly);  
          
        newfill.play();  
          
        Group root = new Group();  
        root.getChildren().addAll(newpoly);  
         Scene scene = new Scene(root,500,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Fill Transition example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the Fill Transition in JavaFX, we have to import all the required libraries such as javafx.animation.FillTransition, javafx.application.Application, javafx.scene.Group, javafx.scene.Scene, javafx.scene.paint.Color, javafx.scene.shape.Polygon, 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 filling polygon, a Group object is created which is then passed to the Scene class object.

The Polygon is created with the help of the constructor and the size parameter and red color to be filled are passed in it. A fill Transition object is created and using setters various properties are set. Then it will show the filling polygon.

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 - Fill Transition Example”. Also, it displays a polygon initially with white color and then get filled with red color.

JavaFX Animation - Fill Transition JavaFX Animation - Fill Transition

JavaFX Animation -Fill Transition on Circle

Example:

import javafx.animation.FillTransition;
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 AnimationUI extends Application {  


    @Override  
    public void start(Stage stage) throws Exception 
    { 
   
    
    Circle newcir = new Circle(250,120,80);  
        
    newcir.setFill(Color.RED);  
    newcir.setStroke(Color.BLACK);  
          
        FillTransition newfill = new FillTransition();  
          
        newfill.setAutoReverse(true);  
          
        newfill.setCycleCount(50);  
          
        newfill.setDuration(Duration.millis(1000));  
          
        newfill.setFromValue(Color.BLUE);  
          
        newfill.setToValue(Color.WHITE);  
          
        newfill.setShape(newcir);  
          
        newfill.play();  
          
        Group root = new Group();  
        root.getChildren().addAll(newcir);  
         Scene scene = new Scene(root,500,450);  
         stage.setScene(scene);  
        stage.setTitle("JavaFx Fill Transition example");  
         stage.show();  
     }
      
    public static void main(String[] args) {  
        launch(args);  
    }  
}

Output:

In order to create the Fill Transition on Circle in JavaFX, we have to import all the required libraries such as javafx.animation.FillTransition, 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 filling 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 the size parameter and blue color to be filled are passed in it. A fill Transition object is created and using setters various properties are set. Then it will show the filling circle.

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 the main() method. In output Frame like container is displayed with the title, " JavaFX Animation - Fill Transition Example”. Also, it displays a circle initially with white color and then gets filled with blue color.

JavaFX Animation - Fill Transition JavaFX Animation - Fill Transition

Related Topics

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.

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

In the JavaFX application, in order to create a Line Chart, LineChart class is used. The LineChart allows us to plot markers point according to the entities on number axes....

4 minutes read.

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

4 minutes read.

JavaFX Color Input

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

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

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

In the JavaFX application, in order to create Bubble Chart, the BubbleChart class is used. The Bubble Chart allows us to plot three dimensional data. All methods needed for 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 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 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.

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