Java Swing How to - Create a JProgressBar Component with an Unknown Maximum








Question

We would like to know how to create a JProgressBar Component with an Unknown Maximum.

Answer

//from   w  w w. ja  v a  2s .  c om
import javax.swing.JProgressBar;

public class Main {
  public static void main(String[] argv) throws Exception {
    // Create a horizontal progress bar
    int min = 0;
    int max = 100;
    JProgressBar progress = new JProgressBar(min, max);

    // Play animation
    progress.setIndeterminate(true);
  }
}