JProgressBar with double value

*爱你&永不变心* 提交于 2019-12-23 23:49:01

问题


Hello i would like to know if i can extends a JProgressBar to use double value for min max, instead of int. Thank you.


回答1:


If you know the bounds and precision of your values, it's quite easy to do with a wrapper. I've used this approach for a computationally intensive application where 1% equates to about 30 seconds. Showing a JProgressBar with min=0 and max=100 didn't give enough feedback. Users thought the application was hung.

Solution: Scale the values

I had a float (0f - 1f) that represented the actual percent complete. By multiplied that by 10000 I got an integer range of 0 - 10000. I set up JPB with min=0 and max=10000.

Then just a call to setString(NumberFormat.getPercentInstance().format(value)) to display the formatted percent.




回答2:


Sure you can, but for what purpose? How do you display a half percent?

You can however use the setString()-method to display the more exact value. Printing the String must be turned on using the setStringPainted()-method.



来源:https://stackoverflow.com/questions/6579789/jprogressbar-with-double-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!