Java JProgressBar class

Introduction

The JProgressBar component can display the progress of some task.

A progress bar may be either in determinate or indeterminate mode.

The following program illustrates how to create this kind of progress bar.

import java.awt.Container;
import java.awt.FlowLayout;

import javax.swing.JFrame;
import javax.swing.JProgressBar;

public class Main {
   public static void main(String args[]) throws Exception {
      JFrame f = new JFrame("java2s.com");
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container c = f.getContentPane();
      f.setSize(200, 80);//from w ww.java 2s . co  m
      f.setLayout(new FlowLayout());
      JProgressBar pb = new JProgressBar(0, 100);
      pb.setStringPainted(true);
      c.add(pb);
      f.setVisible(true);
      for (int i = 0; i <= 100; i++) {
         pb.setValue(i);
         Thread.sleep(100);
      }
   }
}



PreviousNext

Related