[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Stop ProgressBar which is running SWT.INDETERMINATE

OK, last time replying to this thread (for some reason it piqued my
interest).

Anyway, I don't think there's a good way to do exactly what you want, but
you might be able to use this to get close to the same effect:

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;

public class ProgressBarTest {

	public static void main(String[] args) {
		final Display display = new Display();
		final Shell shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
		final org.eclipse.swt.widgets.Composite comp = new org.eclipse.swt.widgets.Composite(shell, SWT.NONE);
		final ProgressBar bar = new ProgressBar(comp, SWT.INDETERMINATE);
		final ProgressBar barComplete = new ProgressBar(comp, SWT.SMOOTH);
		barComplete.setMaximum(2);
		bar.setSize(300, 20);
		barComplete.setSize(300, 20);
		shell.setLayout(new RowLayout());
		shell.pack();
		shell.open();

		new Thread() {
			public void run() {
				try {sleep(5000);} catch (InterruptedException e) {}
				display.syncExec(new Runnable() {
					public void run() {
						barComplete.setSelection(1);
						barComplete.moveAbove(bar);
					}
				});
				try {sleep(5000);} catch (InterruptedException e) {}
				display.syncExec(new Runnable() {
					public void run() {
						barComplete.moveBelow(bar);
					}
				});
			}
		}.start();
		while (!shell.isDisposed ()) {
			if (!display.readAndDispatch ()) display.sleep ();
		}
		display.dispose ();
	}
}


-- 
http://zclipse.org