This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JProgress Bar max value too big.  What to do instead? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JProgress Bar max value too big.  What to do instead?" Watch "JProgress Bar max value too big.  What to do instead?" New topic
Author

JProgress Bar max value too big. What to do instead?

Rob MacKay
Ranch Hand

Joined: Apr 06, 2007
Posts: 35
    
    1
I am using a JProgressBar to represent the total number of bytes being downloaded when grabbing multiple files from a server.

However, during the calculation of the total number of bytes, which is what I use for the max value of the JProgressBar, the value goes outside the range of the 'int' datatype, which will wrap around and possibly give a negative number, breaking the JProgressBar or at the very least, providing an inaccurate value.

What's the best way to solve this problem of the max range being too high?

Should I just covert my bytes to megabytes, which will lose a bit of precision in the progress calculation? Or, if I want to keep the precision of number of downloaded bytes vs the total number to download, how can I get an accurate % to display in the JProgressBar using the long values?



Rob MacKay
Ranch Hand

Joined: Apr 06, 2007
Posts: 35
    
    1
Seems like the best way is to use a simple % calculation of the long total value vs the current value and then call the setString method on the progress bar.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JProgress Bar max value too big. What to do instead?
 
Similar Threads
Losing precision on a number
How does a long fit in a float?
conversion from long to float
a hashkey for double precision numbers
xsd for BigDecimal