wotan2009
wotan2009

Reputation: 151

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. Thank you.

Upvotes: 3

Views: 4395

Answers (2)

Devon_C_Miller
Devon_C_Miller

Reputation: 16528

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.

Upvotes: 6

Lukas Knuth
Lukas Knuth

Reputation: 25755

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.

Upvotes: 4

Related Questions