问题描述:
    我在SWT的主界面上建立了两个按扭,其中一个是执行长任务(需要的完成时间比较长的任务)----显示一个进度条,当我点击这个这个进度按扭后,开始执行进度显示任务,然后就不能再操作界面上的其它主件,当等到进度显示结束后,才能进行其它的住件操作。
   我的进度显示任务是写在Display.getCurrent().syncExec(new Runnable() {})的run方法中的。问题:请问要怎么才能是在执行进度任务的同时,也可以操作其它的swt主件的??
 谢谢!
代码:
public class InnerSetComposite extends org.eclipse.swt.widgets.Composite { {
//Register as a resource user - SWTResourceManager will
//handle the obtaining and disposing of resources
SWTResourceManager.registerResourceUser(this);
} private ProgressIndicator testProgressIndicator;
private Button button3;
private Button button2;
 //private static Shell  shell=null; /**
* Auto-generated main method to display this 
* org.eclipse.swt.widgets.Composite inside a new Shell.
*/
public static void main(String[] args) {
showGUI();
}

/**
* Auto-generated method to display this 
* org.eclipse.swt.widgets.Composite inside a new Shell.
*/
public static void showGUI() {
Display display = Display.getDefault();
Shell shell = new Shell(display);
InnerSetComposite inst = new InnerSetComposite(shell, SWT.NULL);
Point size = inst.getSize();
shell.setLayout(new FillLayout());
shell.layout();
if(size.x == 0 && size.y == 0) {
inst.pack();
shell.pack();
} else {
Rectangle shellBounds = shell.computeTrim(0, 0, size.x, size.y);
shell.setSize(shellBounds.width, shellBounds.height);
}
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
} public InnerSetComposite(org.eclipse.swt.widgets.Composite parent, int style) {
super(parent, style);
initGUI();
} private void initGUI() {
try {
this.setLayout(null);
this.setSize(497, 245);
{
button2 = new Button(this, SWT.PUSH | SWT.CENTER);
button2.setText("进度主件");
button2.setBounds(77, 49, 70, 21);
button2.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
beginIndicater();
}
});
}
testProgressIndicator = new ProgressIndicator(this);
testProgressIndicator.setBounds(196, 56, 252, 14);
testProgressIndicator.setBackground(SWTResourceManager.getColor(192, 192, 192));
{
button3 = new Button(this, SWT.PUSH | SWT.CENTER);
button3.setText("点了进度主键在点我");
button3.setBounds(161, 126, 140, 28);
//button3.setImage(org.jdesktop.jdic.icons.IconService.getIcon("",256));
button3.addSelectionListener(new SelectionAdapter(){
public void widgetSelected(SelectionEvent e){
//Shell shell=new Shell();
// FunctionClass.getDirectoryDialog();
}
});
}
//testProgressIndicator.beginAnimatedTask();

this.layout();
} catch (Exception e) {
e.printStackTrace();
}
}

public void beginIndicater(){

Display.getCurrent().syncExec(new Runnable() {
public void run() {
testProgressIndicator.beginTask(100);
// Inform the indicator that some amount of work has been done
int task=0;
for(int i=0;i<100;i++){
Thread testThread =new Thread();
try {
testThread.sleep(150);
System.out.println( "第"+i+"个任务!");
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
task=i;
testProgressIndicator.worked(1);
}
testProgressIndicator.done();
//testProgressIndicator.setToolTipText("恭喜完成任务");

}
});


}

private void button1MouseDown(MouseEvent evt) {
System.out.println("button1.mouseDown, event=" + evt);
//(new Demo()).setVisible(true);
//Dialog  dailog=new JDialog();
//DateChooser dateChooser=new DateChooser((JFrame)null,"选择日期");
//TODO add your code for button1.mouseDown
}}