在SWT程序中, SWT会自动创建一个用户界面线程,非用户界面线程不能直接操作用户界面线程
要想在另外一个线程中尝试修改用户界面,应采用一下方法:
// If this is the UI thread, then make the change.
if (Display.getCurrent() != null) {
// 修改界面的代码
return;
}
// otherwise, redirect to execute on the UI thread.
Display.getDefault().asyncExec(new Runnable() {
public void run() {
// 修改界面的代码
}
});