There are five different constructors for JProgressBar:
public JProgressBar()
JProgressBar aJProgressBar = new JProgressBar();
public JProgressBar(int orientation)
JProgressBar aJProgressBar = new JProgressBar(JProgressBar.VERTICAL);
JProgressBar bJProgressBar = new JProgressBar(JProgressBar.HORIZONTAL);
public JProgressBar(int minimum, int maximum)
JProgressBar aJProgressBar = new JProgressBar(0, 500);
public JProgressBar(int orientation, int minimum, int maximum)
JProgressBar aJProgressBar = new JProgressBar(JProgressBar.VERTICAL, 0, 1000);
public JProgressBar(BoundedRangeModel model)
// Data model, initial value 0, range 0-250, and extent of 0
DefaultBoundedRangeModel model = new DefaultBoundedRangeModel(0, 0, 0, 250);
JProgressBar aJProgressBar = new JProgressBar(model);
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JProgressBar;
public class JProgressBarSetValue extends JFrame {
JProgressBar bar = new JProgressBar();
JButton step = new JButton("Step");
public JProgressBarSetValue() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
step.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int value = bar.getValue() + 7;
if (value > bar.getMaximum()) {
value = bar.getMaximum();
}
bar.setValue(value);
}
});
getContentPane().add(bar, BorderLayout.NORTH);
getContentPane().add(step, BorderLayout.EAST);
pack();
setVisible(true);
}
public static void main(String arg[]) {
new JProgressBarSetValue();
}
}