SWT Designer allows you to create the views, editors, perspectives, pref pages, composites, etc. that comprise Eclipse SWT & RCP applications and plug-ins.
Moderators: Konstantin.Scheglov, gnebling, Alexander.Mitin, jwren, Eric Clayberg
by nocomm » Tue Sep 23, 2003 3:18 am
hi again
right now i am searching for an example using the progress bar. in my application i start a file system browsing and i want to monitor the progress with the progress bar.
actually i am not really sure, if progress bar is the right tool, as all notes i read so far were quite poor.
maybe it is possible that a short example will be posted here...
that would really be a great help
thanx
nocomm
-
nocomm
-
- Posts: 9
- Joined: Thu Sep 18, 2003 11:53 pm
by admin » Tue Sep 23, 2003 11:50 pm
I also not sure that ProgressBar is good choice, may be you should look at JFace dialog: ProgressMonitorDialog.
Here is sample code for using ProgressBar.
- Code: Select all
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
/**
* @author scheglov_ke
*/
public class TestProgressBar {
private static ProgressBar m_ProgressBar;
private static Display m_Display;
private static int m_Value;
public static void main(String[] args) {
m_Display = new Display();
final Shell shell = new Shell();
shell.setLayout(new GridLayout());
shell.setText("SWT Application");
{
m_ProgressBar = new ProgressBar(shell, SWT.NONE);
m_ProgressBar.setSelection(0);
m_ProgressBar.setMinimum(0);
m_ProgressBar.setMaximum(100);
m_ProgressBar.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
}
{
final Button button = new Button(shell, SWT.NONE);
button.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
handleStartProcess();
}
});
button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_CENTER));
button.setText("&Start process");
}
// DESIGNER: Add controls before this line.
shell.open();
while (!shell.isDisposed()) {
if (!m_Display.readAndDispatch())
m_Display.sleep();
}
}
static void handleStartProcess() {
Thread thread = new Thread() {
public void run() {
try {
m_Value = 0;
for (int i = 0; i < 100; i++) {
m_Display.syncExec(new Runnable() {
public void run() {
m_ProgressBar.setSelection(m_Value);
}
});
m_Value++;
sleep(100);
}
} catch (Throwable e) {
e.printStackTrace();
}
}
};
thread.setDaemon(true);
thread.start();
}
}
-
admin
- Moderator
-
- Posts: 166
- Joined: Thu Jul 24, 2003 12:25 am
-
by nocomm » Wed Sep 24, 2003 12:01 am
thanks a lot, admin!
code looks quite fine for my purpose, I'll try it...
nocomm
-
nocomm
-
- Posts: 9
- Joined: Thu Sep 18, 2003 11:53 pm
Return to SWT Designer
Who is online
Users browsing this forum: Google [Bot], Yahoo [Bot] and 1 guest