Create ProgressBar in Java

Create ProgressBar in Java:

We can use the Eclipse IDE for this example. If you do not know about it then follow this link- How to Install Eclipse For Java and create a program in it.

A ProgressBar is a component that visually displays a value within an interval, and typically represents the progress of a certain task being performed such as software installation, etc. It can be of two types namely, Horizontal ProgressBar and Vertical ProgressBar. In Horizontal ProgressBar, the progress is indicated by filling the bar from left to right, and in Vertical ProgressBar, the progress is indicated by filling the bar from bottom to top.

Java ProgressBar Constructors:

JProgressBar( )Creates a new horizontal ProgressBar that displays a border but no progress string. The initial and minimum values are 0, and the maximum is 100.
JProgressBar(int orient)Creates a new ProgressBar with the specified orientation, which can be either JProgressBar.VERTICAL or JProgressBar.HORIZONTAL.
JProgressBar(int min, int max)Creates a new ProgressBar with the specified minimum value and maximum value.
JProgressBar(int orient, int min, int max)Creates a new ProgressBar with the specified orientation, minimum value and maximum value.

Java ProgressBar Methods:

void setValue(int n)Sets the ProgressBar current value.
void setString(String s)Sets the value of the progress string.
void setOrientation(int newOrientation)Sets the ProgressBar orientation to newOrientation, which must be JProgressBar.VERTICAL or JProgressBar.HORIZONTAL.
void setMinimum(int n)Sets the ProgressBar minimum value.
void setMaximum(int n)Sets the ProgressBar maximum value.

Sample Code to Create ProgressBar in Java:

ProgressBar in Java Code1 - Create ProgressBar in Java
ProgressBar in Java Code 2 - Create ProgressBar in Java


java progressbar code - Create ProgressBar in Java
import java.awt.*;
import javax.swing.*;

public class Progressbar {
	JFrame frame = new JFrame();
	JProgressBar jpb = new JProgressBar(0,100);
		jpb.setBounds(0, 0, 380, 40);
		jpb.setFont(new Font("Open Sans",Font.BOLD,18));
	public void fill(){
		int counter = 0;
		while (counter <= 100) {
			try {
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
			counter += 10;
	public static void main(String[] args) {
		// TODO Auto-generated method stub

		Progressbar pb = new Progressbar();


MySQL Insert Query (Single Row and Multiple Row)
MySQL Select Query with Where Clause
MySQL Commit and Rollback
MySQL Primary Key and Foreign Key
Python Relational Operators or Comparison Operators
Python Logical Operators or Boolean Operators
User Input and Type Casting in Python
List Comprehension in Python
Java (programming language)– Wikipedia

Comments (No)

Leave a Reply