The JProgressBar class is been used to display the progress of any task.

Following are the Commonly used Constructors of JProgressBar class:

  • JProgressBar():-it is used to create a horizontal progress bar but without string text.
  • JProgressBar(int min, int max):-it is used to create a horizontal progress bar within the specified minimum as well as maximum value.
  • JProgressBar(int orient):-it is used to create a progress bar within the specified orientation and it can be either Vertical or Horizontal by using VERTICAL & SwingConstants.HORIZONTAL constants.
  • JProgressBar(int orient, int min, int max):it is used to create a progress bar within the specified orientation along with the minimum as well as maximum value.

Following are the Commonly used methods of the JProgressBar class:

1) public void setStringPainted(boolean b):-it is used to determine whether string be displayed.

2) public void setString(String s):- it is used to set value to progress string.

3) public void setOrientation(int orientation): is used to set the orientation and it may be either vertical or horizontal by using the SwingConstants.VERTICAL & SwingConstants.HORIZONTAL constants.

4) public void setValue(int value): it is used to set current value on the progress bar.

Example is as Follows:-

import java.awt.*;
import javax.swing.*;

public class Progress_Bar1 extends JFrame
{
JProgressBar jb;
int i=0,num=0;

Progress_Bar1()
{
jb=new JProgressBar(0,2000);
jb.setBounds(40,40,200,30);
jb.setValue(0);
jb.setStringPainted(true);
add(jb);
setSize(400,400);
setLayout(null);
}
public void iterate()
{
while(i<=2000)
{
jb.setValue(i);
i=i+20;
try
{
Thread.sleep(150);
}
catch(Exception e)
{
}
}
}
public static void main(String[] args)
{
Progress_Bar1 m=new Progress_Bar1();
m.setVisible(true);
m.iterate();
}
}

Output on top

 

 

CONTACT US

We're not around right now. But you can send us an email and we'll get back to you, asap.

Sending

©2023 MYBSCIT.com. An initiative by some failures to make student scholars.

or

Log in with your credentials

Forgot your details?