The JavaFX ProgressBar is a control capable of displaying the progress of some task. The progress is set as a double value between 0 and 1, where 0 means no progress and 1 means full progress (task completed). The JavaFX ProgressBar control is represented by the javafx.scene.control.ProgressBar class. Here is a screenshot of how a JavaFX ProgressBar looks:

JavaFX ProgressBar with progress set to 0.5

The ProgressBar in the above screenshot has its progress set to 0.5.

JavaFX ProgressBar Example

Here is a full JavaFX ProgressBar code example:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Hyperlink;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class ProgressBarExample extends Application {
    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) {
        primaryStage.setTitle("JavaFX App");

        ProgressBar progressBar = new ProgressBar(0);

        progressBar.setProgress(0.5);

        VBox vBox = new VBox(progressBar);
        Scene scene = new Scene(vBox, 960, 600);

        primaryStage.setScene(scene);
        primaryStage.show();
    }

}

Create a ProgressBar

In order to use a JavaFX ProgressBar you must first create an instance of the ProgressBar class. Here is how you create an instance of a JavaFX ProgressBar:

ProgressBar progressBar = new ProgressBar();

This example creates a ProgressBar in indeterminate mode, meaning its progress level is not known. In indeterminate mode the JavaFX ProgressBar displays an animation.

You can create a ProgressBar instance with a determinate progress level by passing the progress value as parameter to its constructor, like this:

ProgressBar progressBar = new ProgressBar(0);

Setting the Progress Level

You set the progress level of a ProgressBar via the setProgress() method. Here is an example of how you set the progress level of a JavaFX ProgressBar:

ProgressBar progressBar = new ProgressBar(0);

progressBar.setProgress(0.5);