I\'m trying to add a JProgressBar to my program, but it wont update! The value only changes once it reasons 100%. Here\'s my method.
public void downloadImag
images.size()
is an integer, and so is i+1
, so what's happening is the decimal is getting truncated. What you should be doing so something like
main.progressBar.setValue((int)((i+1)/(double)images.size())/100))
What this'll do is it'll ensure that i+1
is being divided by a decimal capable data-type, which'll return the more inclusive data type (double in this case), and then it'll divide a double by an int which'll be no problem because it'll still return a double because it's more inclusive. We then cast that to an int because that's the data type setValue()
wants.