I understand how to do indeterminate progress bars but I don't understand how to do determinate ones. For example say I'm using a JProgressBar
to indicate I am loading a game. In loading this game I have information I want to load in information from some files and initialize variables:
private void load() {
myInt = 5;
myDouble = 1.2;
//initialize other variables
}
And say I have 4 files I want to load information from. How do I translate this to give an accurate loading bar out of 100%?
You need to do the work in a separate thread and update the progress bar's model as the work progresses.
It is important to perform the model updates in the Swing event thread, which can be accomplished by executing the update code with
SwingUtilities.invokeLater
.For example: