简体   繁体   English

具有双值的 JProgressBar

[英]JProgressBar with double value

Hello i would like to know if i can extends a JProgressBar to use double value for min max, instead of int.您好,我想知道我是否可以扩展JProgressBar以使用双精度值作为最小值最大值,而不是 int。 Thank you.谢谢你。

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.我已经将这种方法用于计算密集型应用程序,其中 1% 相当于大约 30 秒。 Showing a JProgressBar with min=0 and max=100 didn't give enough feedback.显示min=0max=100JProgressBar并没有提供足够的反馈。 Users thought the application was hung.用户认为应用程序已挂起。

Solution: Scale the values解决方案:缩放值

I had a float (0f - 1f) that represented the actual percent complete.我有一个代表实际完成百分比的浮点数(0f - 1f)。 By multiplied that by 10000 I got an integer range of 0 - 10000. I set up JPB with min=0 and max=10000.乘以 10000,我得到 integer 范围为 0 - 10000。我将 JPB 设置为 min=0 和 max=10000。

Then just a call to setString(NumberFormat.getPercentInstance().format(value)) to display the formatted percent.然后只需调用setString(NumberFormat.getPercentInstance().format(value))即可显示格式化的百分比。

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.但是,您可以使用setString() - 方法来显示更准确的值。 Printing the String must be turned on using the setStringPainted() -method.必须使用setStringPainted()方法打开打印字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM