JavaFX ProgressBar
In the JavaFX application, in order to show the progress of work ProgressBar is used. It shows how much work is done. In order to use ProgressBar in JavaFX, javafx.scene.control.ProgressBar class is used.
JavaFX ProgressBar:
Example:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class ProgressBarUI extends Application {
@Override
public void start(Stage primaryStage) throws Exception
{
StackPane pane = new StackPane();
ProgressBar newprogress = new ProgressBar();
pane.getChildren().add(newprogress);
Scene scn = new Scene(pane, 400, 200);
primaryStage.setScene(scn);
primaryStage.setTitle("JavaFx Progress bar Example");
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
Output:
In order to create the ProgressBar in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Scene, javafx.stage.Stage, javafx.scene.control.ProgressBar, javafx.scene.layout.StackPane.
Then we have created one class named ProgressBarUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold ProgressBar, a StackPane object is created which is then passed to the Scene class object.
The ProgressBar is created with its constructor.
The stage is prepared, the title is set and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, “ JavaFX Progress bar Example ”. Also, it displays Simple ProgressBar.
JavaFX ProgressBar with setProgress() method:
Example:
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.ProgressBar;
import javafx.scene.layout.StackPane;
import javafx.stage.Stage;
public class ProgressBarUI extends Application {
@Override
public void start(Stage primaryStage) throws Exception
{
StackPane pane = new StackPane();
ProgressBar newprogress = new ProgressBar();
newprogress.setProgress(0.5f);
pane.getChildren().add(newprogress);
Scene scn = new Scene(pane, 400, 200);
primaryStage.setScene(scn);
primaryStage.setTitle("JavaFx Progress bar Example");
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
Output:
In order to create the ProgressBar with progress level set in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.scene.Scene, javafx.stage.Stage, javafx.scene.control.ProgressBar, javafx.scene.layout.StackPane.
Then we have created one class named ProgressBarUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold ProgressBar with 0.5 level. A StackPane object is created which is later on passed to the Scene class object.
The ProgressBar is created with its constructor. The setProgress() method is used to set the level of progress in ProgressBar.
The stage is prepared, the title is set, and the show() method is called to display output. In order to run the application, the launch(args) method is called in the main() method. In output Frame like container is displayed with the title, “ JavaFX Progress bar Example ”. Also, it displays ProgressBar with a 0.5 level.
JavaFX Progress Bar with Progress Indicator:
Example:
import javafx.application.Application;
import javafx.stage.Stage;
import javafx.scene.Scene;
import javafx.geometry.Insets;
import javafx.scene.Group;
import javafx.scene.control.ProgressBar;
import javafx.scene.control.ProgressIndicator;
import javafx.scene.layout.HBox;
import javafx.scene.paint.Color;
public class ProgressBarUI extends Application {
@Override
public void start(Stage primaryStage) throws Exception
{
ProgressBar newprogress = new ProgressBar();
newprogress.setProgress(0.4);
ProgressIndicator newindicator = new ProgressIndicator(0.4);
newprogress.setPrefSize(300, 30);
HBox hbox = new HBox(20);
hbox.setSpacing(15);
hbox.setPadding(new Insets(75, 150, 50, 60));
hbox.getChildren().addAll(newprogress, newindicator);
Group pane = new Group(hbox);
Scene scn = new Scene(pane, 600, 400);
primaryStage.setScene(scn);
primaryStage.setTitle("JavaFx Progress bar Example");
primaryStage.show();
}
public static void main(String[] args) {
Application.launch(args);
}
}
Output:
In order to create the ProgressBar with progress indicator and level set in JavaFX, we have to import all the required libraries such as javafx.application.Application, javafx.stage.Stage, javafx.scene.Scene, javafx.geometry.Insets, javafx.scene.Group, javafx.scene.control.ProgressBar, javafx.scene.control.ProgressIndicator, javafx.scene.layout.HBox, and javafx.scene.paint.Color.
Then we have created one class named ProgressBarUI extending the Application class. Also, we have to override the start method to provide implementation details. This method creates an object of Stage as primaryStage. For the container to hold ProgressBar with 0.4 level and progress indicator with 0.4 level. Group is created and later on passed to the Scene class object.
The ProgressBar is created with its constructor. The setProgress() method is used to set the level of progress in ProgressBar. ProgressIndicator is created using its constructor with a level passed in it.
The stage is prepared, the title is set and the show() method is called to display output. The launch(args) method is called. In output Frame like container is displayed with the title, “ JavaFX Progress bar Example ”. Also, it displays ProgressBar with 0.4 level and progress indicator with the same level.