There are many posts on JProgressBar, but I can not find a solution for the following problem. How do I update JProgressBar measuring bytes received from InputStream?
For example, I have the following code:
int bytesRead;
byte buffer = new byte[1024];
ByteArrayOutputStream getBytes = new ByteArrayOutputStream();
while ((bytesRead = dis.read(buffer)) != -1) {
getBytes.write(buffer, 0, bytesRead);
}
return(getBytes.toByteArray());
If you know how many bytes you will be reading, you can set that as the max and increment the progress bar by the number of bytes read for each iteration of the loop.
If you don't know how many bytes you will read, set the progress bar to indeterminate mode and it will animate itself showing that "some" progress is occurring.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With