So i'm trying to make a downloader which shows the progress of the download with a progress bar. But i'm having problems since it doesn't actually update the progress bar. Basically it stays white, when it is meant to be blue. If anyone could help, code is below.
JProgressBar progressBar = new JProgressBar(0, ia);
con.add(progressBar, BorderLayout.PAGE_START);
con.validate();
con.repaint();
progressBar = new JProgressBar(0, ia);
progressBar.setValue(0);
System.out.print("Downloading Files");
while ((count = in.read(data, 0, downloadSpeed)) != -1){
fout.write(data, 0, count);
if (count >= 2){
progressBar.setString("Downloading : " + ia + " @ " + count + "Kbs per second");
} else {
progressBar.setString("Downloading : " + ia + " @ " + count + "Kb per second");
}
progressBar.setValue(count);
con.add(progressBar, BorderLayout.PAGE_START);
try{
Thread.sleep(1000);
} catch (Exception e){}
}
Use a combination with SwingWorker. See an example here: SwingWorker and Progress Bar
@Hovercraft: You're right. Allow me to refer to the corresponding SwingWorker page of JavaDoc, in my opinion this explains the situation best.