Create a JProgressBar Component with an Unknown Maximum in Java
Description
The following code shows how to create a JProgressBar Component with an Unknown Maximum.
Indeterminate mode: Progress bar bounces back and forth from side to side
Example
// w w w. j a va2 s .c o m
import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
public class Main extends JFrame {
public Main() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
int min = 0;
int max = 100;
JProgressBar progress = new JProgressBar(min, max);
// Play animation
progress.setIndeterminate(true);
getContentPane().add(progress, BorderLayout.NORTH);
pack();
setVisible(true);
}
public static void main(String arg[]) {
new Main();
}
}
The code above generates the following result.
Home »
Java Tutorial »
Swing »
Java Tutorial »
Swing »