Saturday 23 June 2018

JavaFX: ProgressBar: Working with progress bar

JavaFX provides ProgressBar and ProgressIndicator widgets to visualize the progress of operations (Ex: How much copy is done, how much installation finished etc.,).

In this post, I am going to explain about ProgressBar widget.

ProgressBar class provides below constructors to create progress bar widget.
public ProgressBar()
public ProgressBar(double progress)

Example 1
ProgressBar progressBar1 = new ProgressBar();
progressBar1.setProgress(0.4);

Example 2
ProgressBar progressBar2 = new ProgressBar(0.6);

Find the below working application.

ProgressBarApp.java
package com.sample.demos;

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

public class ProgressBarApp extends Application {

 @Override
 public void start(Stage primaryStage) throws Exception {
  ProgressBar progressBar1 = new ProgressBar();
  progressBar1.setProgress(0.4);

  ProgressBar progressBar2 = new ProgressBar(0.6);

  VBox vBox = new VBox(20, progressBar1, progressBar2);

  Scene scene = new Scene(vBox);

  primaryStage.setScene(scene);

  primaryStage.setTitle("Progress Bar widget Example");
  primaryStage.setWidth(900);
  primaryStage.setHeight(500);
  primaryStage.show();
 }

}

TestFX.java
package com.sample.demos;

import javafx.application.Application;

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



      ProgressBar: Inderterminate progress bar
      Working with ProgressIndicator widget
      ProgressIndicator: Inderterminate progress bar

Previous                                                 Next                                                 Home

No comments:

Post a Comment