Hallo Torsten,
basierend auf deinem Vorschlag habe ich jetzt mal eine Test-Klasse geschrieben. Allerdings noch immer mit dem gleichen Ergebnis: GUI hält an bis die Berechnung fertig ist.
Hier die Klasse (mit sinnloser Berechnung, was aber egal ist):
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.ProgressBar;
import org.eclipse.swt.widgets.Shell;
/**
*
* Klasse zum Test der ProgressBar-Funktionalität
*
*/
public class ProgressTest {
Display display;
private Shell shell;
Composite upComposite;
Composite downComposite;
ProgressBar pb;
ProgressBar pb2;
Label label;
/**
*
*/
public ProgressTest() {
this.display = new Display();
this.shell = new Shell();
this.shell.setText(„ProgressTest“);
this.shell.setSize(400, 200);
createGUI();
this.shell.open();
while (!this.shell.isDisposed()) {
if (!this.display.readAndDispatch())
this.display.sleep();
}
}
private void createGUI() {
this.shell.setLayout(new GridLayout());
/**
* oben
*/
this.upComposite = new Composite(this.shell, SWT.BORDER);
this.upComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
this.upComposite.setLayout(new GridLayout(1, false));
Button goButton = new Button(this.upComposite, SWT.FLAT);
goButton.setText(„GO“);
goButton.setLayoutData(new GridData(80, 20));
goButton.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent arg0) {
process_go();
}
});
this.pb = new ProgressBar(this.upComposite, SWT.SMOOTH);
this.pb.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
this.pb.setMaximum(100);
this.pb.setMinimum(0);
this.pb2 = new ProgressBar(this.upComposite, SWT.SMOOTH
| SWT.INDETERMINATE);
this.pb2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
/**
* unten
*/
this.downComposite = new Composite(this.shell, SWT.BORDER);
this.downComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
this.downComposite.setLayout(new GridLayout(1, false));
this.label = new Label(this.downComposite, SWT.NONE);
this.label.setLayoutData(new GridData(GridData.FILL_BOTH));
this.label.setText(„press „GO“ to start“);
}
protected void process_go() {
this.label.setText("…");
double summe = berechnen();
this.label.setText("Summe: " + Math.round(summe));
}
/**
* @return int
*
*/
public double berechnen() {
Berechnung myBerechnung = new Berechnung(this);
this.display.syncExec(myBerechnung);
return myBerechnung.getSum();
}
/**
* @param value
*/
public void neueAnzeige(final int value) {
this.display.asyncExec(new Runnable() {
public void run() {
ProgressTest.this.pb.setSelection(value);
}
});
}
/**
* @param args
*/
public static void main(String[] args) {
new ProgressTest();
}
}
/**
*
* Berechnung: Runnable
*
*/
class Berechnung implements Runnable {
private ProgressTest myTest;
private double sum = 1;
/**
*
* @param myTest
*/
public Berechnung(ProgressTest myTest) {
this.myTest = myTest;
}
public void run() {
for (int i = 0; i