• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 35
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 35
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic