Set all the values at once by using the model for JProgressBar in Java
Description
The following code shows how to set all the values at once by using the model for JProgressBar.
Example
// w w w . ja va 2s.c om
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 minimum = 0;
int maximum = 100;
JProgressBar progress = new JProgressBar(minimum, maximum);
int newValue = 10;
int newMin = 0;
int newMax = 100;
progress.getModel().setRangeProperties(newValue, 0, newMin, newMax, false);
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 »