1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| public static void main(final String[] args) {
final Display display = new Display();
final Shell shell = new Shell(display);
shell.setLayout(new GridLayout(1, false));
final Composite composite = new Composite(shell, SWT.NONE);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
composite.setLayout(new GridLayout(1, false));
final ProgressBar bar = new ProgressBar(composite, SWT.ON_TOP | SWT.SMOOTH);
bar.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
bar.setSize(200, 32);
final int maximum = bar.getMaximum();
new Thread(new Runnable() {
@Override
public void run() {
for (final int[] i = new int[1]; i[0] < maximum; i[0]++) {
try {
Thread.sleep(100);
} catch (final Throwable th) {
}
if (display.isDisposed())
return;
display.asyncExec(new Runnable() {
@Override
public void run() {
if (bar.isDisposed())
return;
bar.setSelection(i[0]);
}
});
if (i[0] == (maximum - 1)) {
display.asyncExec(new Runnable() {
@Override
public void run() {
if (bar.isDisposed()) {
return;
}
bar.setSelection(maximum);
}
});
try {
Thread.sleep(1000);
} catch (final Throwable th) {
}
display.asyncExec(new Runnable() {
@Override
public void run() {
final Shell activeShell = display.getActiveShell();
if (activeShell != null && !activeShell.isDisposed()) {
activeShell.close();
}
}
});
}
}
}
}).start();
shell.setText("Progress test");
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
} |