Java Swing How to - Display the Percentage Done on a JProgressBar Component








Question

We would like to know how to display the Percentage Done on a JProgressBar Component.

Answer

//  ww  w  .  java 2  s  .  c o m
import javax.swing.JProgressBar;

public class Main {
  public static void main(String[] argv) throws Exception {
    int minimum = 0;
    int maximum = 100;
    JProgressBar progress = new JProgressBar(minimum, maximum);

    // Overlay a string showing the percentage done
    progress.setStringPainted(true);

  }
}