I have created a for loop that counts from 0 to 850000. I have chosen a high number because I want to create a progress bar that will update using the results in the for loop. Here is the code that I have so far.
public class ProgressBarTest extends JFrame {
private JPanel contentPane;
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
ProgressBarTest frame = new ProgressBarTest();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public ProgressBarTest() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 450, 300);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPane.setLayout(new BorderLayout(0, 0));
setContentPane(contentPane);
for(int i = 850000; i>0; i--) {
System.out.println("i = " + i);
}
}
}
I cannot seem to find a way to get a progress bar to update using a for loop. I did create a progress bar that worked on a timer but that is not what I want it to do. I basically want it to update from 0% to 100%. This does seem simple to me but I have been stuck on it for a while. I appreciate any sort of sample code that will help me to understand how it works.