JProgressBar class in java

JProgressBar class

A progress bar visually display the progress of some task. As the task progresses towards completion, the progress bar displays the tasks percentage of completion.

Constructors

  • JProgressBar()
  • JProgressBar(int min, int max)
  • JProgressBar(int orient)
  • JProgressBar(int orient, int min, int max):

Methods

  • public void setStringPainted(boolean b)
  • public void setString(String s)
  • public void setOrientation(int orientation)
  • public void setValue(int value)
Example
import javax.swing.*;
public class test extends JFrame
{
JProgressBar jb;
int i=0,num=0;
test()
{
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)
{
test t=new test();
t.setVisible(true);
t.iterate();
}
}

Output:

Untitled

Leave a Reply

Your email address will not be published. Required fields are marked *