×

JavaFX ProgressBar

In the JavaFX application, in order to show the progress of work ProgressBar is used. It shows how much work is done. In order to use ProgressBar in JavaFX, javafx.scene.control.ProgressBar class is used.

JavaFX ProgressBar:

Example:

import javafx.application.Application;


import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;  


  
public class ProgressBarUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
      StackPane pane = new StackPane();  
      ProgressBar newprogress = new ProgressBar();  
      pane.getChildren().add(newprogress);  
        Scene scn = new Scene(pane, 400, 200);
        primaryStage.setScene(scn);  
        primaryStage.setTitle("JavaFx Progress bar Example");  
        primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the ProgressBar in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Scene, javafx.stage.Stage, javafx.scene.control.ProgressBar, javafx.scene.layout.StackPane.

Then we have created one class named ProgressBarUI 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 ProgressBar, a StackPane object is created which is then passed to the Scene class object.

The ProgressBar is created with its constructor.

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 Progress bar Example ”. Also, it displays Simple ProgressBar.

JavaFX ProgressBar

JavaFX ProgressBar with setProgress() method:

Example:

import javafx.application.Application;


import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;  


  
public class ProgressBarUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    StackPane pane = new StackPane();  
        ProgressBar newprogress = new ProgressBar();  
        newprogress.setProgress(0.5f);  


        pane.getChildren().add(newprogress);  
        Scene scn = new Scene(pane, 400, 200);
        primaryStage.setScene(scn);  
        primaryStage.setTitle("JavaFx Progress bar Example");  
        primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the ProgressBar with progress level set in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Scene, javafx.stage.Stage, javafx.scene.control.ProgressBar, javafx.scene.layout.StackPane.

Then we have created one class named ProgressBarUI 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 ProgressBar with 0.5 level. A StackPane object is created which is later on passed to the Scene class object.

The ProgressBar is created with its constructor. The setProgress() method is used to set the level of progress in ProgressBar.

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 Progress bar Example ”. Also, it displays ProgressBar with a 0.5 level.

JavaFX ProgressBar

JavaFX Progress Bar with Progress Indicator:

Example:

import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;


  
public class ProgressBarUI extends Application {  


    @Override  
    public void start(Stage primaryStage) throws Exception 
    {  
    ProgressBar newprogress = new ProgressBar();
    newprogress.setProgress(0.4);
        ProgressIndicator newindicator = new ProgressIndicator(0.4);
        newprogress.setPrefSize(300, 30);
        HBox hbox = new HBox(20);
        hbox.setSpacing(15);
        hbox.setPadding(new Insets(75, 150, 50, 60));
        hbox.getChildren().addAll(newprogress, newindicator);
        Group pane = new Group(hbox);
        Scene scn = new Scene(pane, 600, 400);
        primaryStage.setScene(scn);  
        primaryStage.setTitle("JavaFx Progress bar Example");  
        primaryStage.show();  
        }
    public static void main(String[] args) {
        Application.launch(args);
    }
}

Output:

In order to create the ProgressBar with progress indicator and level set in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.geometry.Insets, javafx.scene.Group, javafx.scene.control.ProgressBar, javafx.scene.control.ProgressIndicator, javafx.scene.layout.HBox, and javafx.scene.paint.Color.

Then we have created one class named ProgressBarUI 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 ProgressBar with 0.4 level and progress indicator with 0.4 level. Group is created and later on passed to the Scene class object.

The ProgressBar is created with its constructor. The setProgress() method is used to set the level of progress in ProgressBar. ProgressIndicator is created using its constructor with a level passed in it.

The stage is prepared, the title is set and the show() method is called to display output. The launch(args) method is called. In output Frame like container is displayed with the title, “ JavaFX Progress bar Example ”. Also, it displays ProgressBar with 0.4 level and progress indicator with the same level.

JavaFX ProgressBar

Related Topics

JavaFX TextField

In the JavaFX application, to get the user information as input from the user, a form is created using textfields which allows the user to enter input for specific fields....

4 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 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 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 - Basic Structure of Application

Every JavaFX application is mainly divided into three main components namely Scene, Stage, and nodes. For using these components we need to import javafx.application.Application class in every javafx application. Life...

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

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

4 minutes read.

JavaFX Rectangle

In the JavaFX application, in order to draw a rectangle, the Rectangle class is used. The Rectangle allows us to join any four points with x and y coordinates in...

4 minutes read.

JavaFX Button Styling

 In the JavaFX application, we can apply CSS styling to buttons in various ways. We can change the size of the button as well as border colour, text colour can...

3 minutes read.

JavaFX PasswordField

In the JavaFX application, to get the user information and password as input from the user, a form is created using textfields and password fields which allows the user to...

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 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 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 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 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 colors in these shapes using the setFill()...

6 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 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 Gaussian Blur

In the JavaFX application, in order to apply various Gaussian blur effect, we use GaussianBlur class. It has the ability to apply blur effect on the given object. All methods...

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