Swing JProgessBar

In this tutorial you will learn about the Swing JProgessBar and its application with practical example.

Swing JProgessBar

JProgressBar is used to displays the progress of some task. As the task progresses towards completion , the progress bar displays task’s percentage of completion.

Table Of Contents

JProgessBarClass Declaration

JProgessBar Constructor

Let’s get more understand about JProgressBaar, Some of important constructor are listed below.

JProgressBar(): This constructor is used to construct a horizontal progress bar without progress string.

JProgessBar(BoundedRangModel newModel): This constructor is used to construct a horizontal progress bar that hold the progress bar’s data of specified model.

JProgressBar(int orient): This constructor construct a progress bar with given orientation, it may be SwingConstant.VERTICAL or SwingConstant.Horizontal.

JProgressBar(int min, int max): This constructor construct a horizontal progress bar with the minimum and maximum given value.

JProgressBar(int orient, int min, int max): This constructor construct a progress bar with minimum , maximum and given orientation.

JProgessBar Method

Some of commonly used methods are listed below. It will help to know more about JProgressBar

void addChangeListener(ChangeListener l): This method is used to add the specified ChangeListener to the progress bar.

int getValue(): It returns current progress value of Progress Bar.

boolean isIndeterminate(): This method returns the value of the indeterminate property.

void setIndeterminate(boolean value): This method is used to set Indeterminate value of Progress Bar , which specified that the progress bar will be determinate or indeterminate.

void setMaximum(int n): It sets the maximum progress value of progress bar.

void setMinimum(int n): It sets the minimum progress value of progress bar.

void setString(String s): it is used to set the value of the progress string.

void setValue(int n):This method is used to sets the “n”current progress value to the Progress Bar.

Example :-

An simple example to get understand about JProgressBar. Hopefully this will work for you.

Output :-

Output of this code will look like below image. You just need to copy this code and paste it in you program.

image001

In this tutorial we have learn about the Swing JProgessBar and its application with practical example. I hope you will like this tutorial.