JavaFX | ProgressIndicator

ProgressIndicator is a part of JavaFX package. It’s a circular control which is used for indicating progress, either infinite or finite. Often used with the Task API for representing the progress of background Tasks. It usually shows the amount of completion of a task.

Constructor of the class are

  1. ProgressIndicator(): creates a new intermediate progress Indicator.
  2. ProgressIndicator(double p): creates a progress Indicator with a sepcified progress

Commonly used methods

method explanantion
isIndeterminate() Gets the value of the property indeterminate.
getProgress() Gets the value of the property progress.
setProgress(double v) Sets the value of the property progress

Below program illustrate the use of Progress Indicator:

Program to create Progress indicator: This program creates a progress indicator indicated by the name pb. The progress indicator will be created inside a scene, which in turn will be hosted inside a stage. The function setTitle() is used to provide title to the stage. Then a tile pane is created, on which addChildren() method is called to attach the progress indicator and the button inside the scene. Finally the show() method is called to display the final results.

filter_none

edit
close

play_arrow

link
brightness_4
code

// Java program to illustrate the use of Progress Indicator
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.layout.*;
import java.io.*;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.control.Label;
import javafx.stage.Stage;
import java.net.*;
public class progressi extends Application {
  
    static double ii = 0;
  
    // launch the application
    public void start(Stage s) throws Exception
    {
        // set title for the stage
        s.setTitle("creating progressIndicator");
  
        // create a progress indicator
        ProgressIndicator pb = new ProgressIndicator();
  
        // create a tile pane
        TilePane r = new TilePane();
  
        // action event
        EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() {
            public void handle(ActionEvent e)
            {
                // set progress to different level of progressindicator
                ii += 0.1;
                pb.setProgress(ii);
            }
  
        };
  
        // creating button
        Button b = new Button("increase");
  
        // set on action
        b.setOnAction(event);
  
        // add button
        r.getChildren().add(pb);
        r.getChildren().add(b);
  
        // create a scene
        Scene sc = new Scene(r, 200, 200);
  
        // set the scene
        s.setScene(sc);
  
        s.show();
    }
  
    public static void main(String args[])
    {
        // launch the application
        launch(args);
    }
}

chevron_right


Output:

Note : The following Programs might not run in an online IDE please use an offline Compiler.
Reference: https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/ProgressIndicator.html



My Personal Notes arrow_drop_up

Second year Department of Information Technology Jadavpur University

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.