标题: Access the SWT widget in other Thread [打印本页] 作者: wangsong2 时间: 2006-05-25 09:08 标题: Access the SWT widget in other Thread SWT widget is not accessible out of the SWT main thread. we must play some trick here.
example:
class LocationControl extends Thread {
private CustomLocation location;
public void setLocation(CustomLocation location) {
this.location=location;
}
public void run() {
while ( true ) {
location.x=location.x+2;
try {
sleep(100);
} catch ( Exception e ) {}
Display.getDefault().asyncExec(new Runnable() {
public void run() {
shell.redraw();
}
});
}
}
}
and in the main Thread , we can just start the Thread, the shell
should be redrawed every 100 ms.