Set value for Progress Bars - Java Swing

Java examples for Swing:JProgressBar

Description

Set value for Progress Bars

Demo Code

import java.awt.FlowLayout;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
import javax.swing.JTextArea;

public class Main extends JFrame {

  JProgressBar current;// w ww.j  ava 2  s .  co m
  JTextArea out;
  JButton find;
  Thread runner;
  int num = 0;

  public Main() {
    super("Progress Monitor");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setSize(205, 68);
    setLayout(new FlowLayout());
    current = new JProgressBar(0, 2000);
    current.setValue(0);
    current.setStringPainted(true);
    add(current);
  }

  public void iterate() {
    while (num < 2000) {
      current.setValue(num);
      try {
        Thread.sleep(1000);
      } catch (InterruptedException e) {
      }
      num += 95;
    }
  }

  public static void main(String[] arguments) {
    Main frame = new Main();
    frame.setVisible(true);
    frame.iterate();
  }
}

Related Tutorials