JProgressBar wont update

后端 未结 3 1379
挽巷
挽巷 2020-12-04 02:57

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         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-04 03:30

    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.

提交回复
热议问题