JavaFX Progress Bar

0

JavaFX Progress tutorials:

The JavaFX Progress Bar is UI control which is used to visualize progress of an operation in JavaFX applications.
It is a horizontal bar to show progress from left to right.

Constructors :

  • ProgressBar()
    Creates a new indeterminate ProgressBar.
  • ProgressBar(double progress)
    Creates a new ProgressBar with the given progress value.

Creating progress bar :

ProgressBar pb = new ProgressBar();

setProgress() method is used to set the starting progress of progress bar.

Example using Progress bar:


package javafxtuts;
import javafx.application.Application;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;

public class Javafxtuts extends Application {

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

  @Override
  public void start(Stage stage) {
      stage.setTitle("Javafxtuts.com");
      Label lb=new Label(" Progress Bar ");
      ProgressBar pb = new ProgressBar();
      pb.setProgress(0.40F);
      VBox root =new VBox();
      root.setPadding(new Insets(20, 10, 10, 10));
      root.getChildren().addAll(lb,pb);
        Scene scene = new Scene(root, 250, 200);
        stage.setScene(scene);
        stage.show();
  }
}

Output :

Explanation of progress bar example :

    • Creating a new progress bar as
      ProgressBar pb = new ProgressBar();
    • pb.setProgress(0.40F);
      It set progress to 40/100
Share.

Leave A Reply