[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[news.eclipse.platform.swt] Re: SWT Event Dispatching in new Runnable() - SWT on Mac OS X 10.4.1

Hi Jacoby ,

If I understand the issue correctly here, it looks like you want to get back onto the UI thread from another thread.

Thread longTask = new Thread(new Runnable() {

Display.getDefault().asyncExec(new Runnable() {
public void run() {
//update the UI components here
}
});

});

asyncExec will get you back on to the Event Dispatch (UI thread), syncExec will do the same but will block until the the GUI is finished updating.

-Dano

Jacoby Thwaites wrote:
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();
}
}