I'm probably being really dim here.
The snippet below correctly displays a shell if I invoke test.run() inline.
But if I try to start a new thread called (say) ui to do the job, no dice.
The shell appears, but d.sleep() never exits in response to any mouse
action, so the shell effectively hangs.
The SWT JavaDocs say that the thread that creates a Display is the UI thread
by definition, so what is going wrong?
public class Test implements Runnable {
public void run() {
Display d = new Display();
Shell s = new Shell(d);
s.setSize(500, 500);
s.open();
while (!s.isDisposed()) {
if (!d.readAndDispatch())
d.sleep();
}
d.dispose();
}
}
public static void main(String[] args) throws Exception {
Test test = new Test();
//test.run(); // THIS WORKS FINE (IF UNCOMMENTED!)
// THIS DOESN"T WORK - WINDOW APPEARS BUT UI THREAD SEES NO EVENTS
Thread ui = new Thread( test, "Test thread");
ui.start();
ui.join();
}
}