Saturday 23 June 2018

JavaFX: ProgressIndicator: Inderterminate progress bar

Sometimes application may not know, how long the execution takes. In those cases, you can set the progress bar to indeterminate state.

How to set the progress bar state to indeterminate?
If you create ProgressIndicatorwidget using default constructor, it will be in indeterminate state. You can also set the ProgressIndicator to indeterminate state by setting the progress to 'INDETERMINATE_PROGRESS'.

Example 1
ProgressIndicator progressIndicator1 = new ProgressIndicator();

Example 2
ProgressIndicator progressIndicator2 = new ProgressIndicator(0.6);
progressIndicator2.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS);

Find the below working application.

ProgressIndicatorApp.java
package com.sample.demos;

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

public class ProgressIndicatorApp extends Application {

 @Override
 public void start(Stage primaryStage) throws Exception {
  ProgressIndicator progressIndicator1 = new ProgressIndicator();

  ProgressIndicator progressIndicator2 = new ProgressIndicator(0.6);
  progressIndicator2.setProgress(ProgressIndicator.INDETERMINATE_PROGRESS);

  VBox vBox = new VBox(20, progressIndicator1, progressIndicator2);

  Scene scene = new Scene(vBox);

  primaryStage.setScene(scene);

  primaryStage.setTitle("Progress Indicator widget Example");
  primaryStage.setWidth(500);
  primaryStage.setHeight(400);
  primaryStage.show();
 }

}

TestFX.java
package com.sample.demos;

import javafx.application.Application;

public class TestFX {
 public static void main(String args[]) {
  Application.launch(ProgressIndicatorApp.class, args);
 }
}




Previous                                                 Next                                                 Home

No comments:

Post a Comment