I want to use JProgressBar
to monitor the progress of copying the contents of a byte array to a JTextArea
. In fact, I've read to many tutorials about that but I am still getting a stuck in the following piece of code:
byte[] encodedImg = bOut.toByteArray();
int length = encodedImg.length;
int current = 0;
JProgressBar progressBar = new JProgressBar();
progressBar.setMaximum(length);
progressBar.setValue(0);
ByteArrayOutputStream out = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int bytesReadSoFar = 0;
while(length != -1)
{
out.write(buffer);
current += bytesReadSoFar;
textArea.setText(String.valueOf(buffer));
progressBar.setValue(current);
}
Unfortunately, I still can't get the progress as I want. Could anyone hint me please.