具有双值的 JProgressBar [英] JProgressBar with double value
问题描述
您好,我想知道我是否可以扩展 JProgressBar
以使用最小最大值的双值,而不是整数.谢谢.
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% 相当于大约 30 秒.显示带有 min=0
和 max=100
的 JProgressBar
没有给出足够的反馈.用户认为应用程序已挂起.
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.
解决方案:缩放值
我有一个浮点数 (0f - 1f) 代表实际完成百分比.通过将其乘以 10000,我得到了 0 - 10000 的整数范围.我设置了 JPB 的 min=0 和 max=10000.
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.
然后只需调用 setString(NumberFormat.getPercentInstance().format(value))
即可显示格式化的百分比.
Then just a call to setString(NumberFormat.getPercentInstance().format(value))
to display the formatted percent.
这篇关于具有双值的 JProgressBar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!