My program reads files from a directory on the filesystem. I have a progress bar that has minimum set to 0 and a maximum set to n(number of files in particular directory). Above it is a piece of text which displays the progress of the iterations... 1/100, 2/100, 3/100 etc.
The problem I'm having is the text displayed is never in sync with the progress bar. The progress bar will be at around 70% when the text says 100/100. Can anybody help me with this?
pb1.setMinimum(0);
pb1.setMaximum(files2.size());
shell.getDisplay().asyncExec(new Runnable() {
public void run() {
if (pb1.isDisposed()) return;
for(final File f : files2) {
pb1.setSelection(pb1.getSelection() + 1);
dialogShell.setText("Loading" + pb1.getSelection() +
"/"+pb1.getMaximum());
}
}
});
try using a 'counter' in your thread like
pb1.setMinimum(0);
pb1.setMaximum(files2.size());
shell.getDisplay().asyncExec(new Runnable() {
public void run() {
int n = pb1.getMinimum();
int d = pb1.getMaximum();
if (pb1.isDisposed()) { return; }
for(final File f:files2){
pb1.setSelection(n);
dialogShell.setText("Loading "+n+"/"+d);
n++;
}
}
});
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