Java 编程 能否在线程中使用SWT创建一个对话框?

来源:百度知道 编辑:UC知道 时间:2024/06/24 08:19:21
如下代码,运行时错误,请高手指点!
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.MessageBox;
import org.eclipse.swt.widgets.Shell;

public class SWTMessageBox {

protected Shell shell;

/**
* Launch the application
* @param args
*/
public static void main(String[] args) {
try {
SWTMessageBox window = new SWTMessageBox();
window.open();
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* Open the window
*/
public void open() {
final Display display = Display.getDefault();
createContents();
shell.open();
shell.layout();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
}

/**
* Create contents of the window
*/
protected void createContents() {
shell = new She

运行时啥错误啊

只有ui才能run wedget的线程,其他地方想执行线程要用exec方法

关于SWT的线程问题,必须用Display.getCurrent().asyncExec(Runaable r)开启