user816526
user816526

Reputation: 25

How do I fire a custom event in SWT?

I am building an application in swt, I also have a thread running which polls the database for any changes (made directly to the db or by another application).

I am able to pick up the changes but I now need to tell my interface to refresh, I tried calling the objects refresh method (that I made) directly from the thread but I get an SWTException "Invalid Thread Access".

Is there a way to create my own event inside the thread which can then be manually fired upon finding a change on the database, which is then picked up by the class that needs to be refreshed.

I have looked at SWT events but I can only seem to find ones which are attached to widgets and can only be fired through the widget itself...

Thanks!

Upvotes: 0

Views: 1137

Answers (1)

Andy Thomas
Andy Thomas

Reputation: 86429

You need to update the user interface from the user-interface thread.

One way to do that is to use one of these methods on the org.eclipse.swt.widgets.Display class:

Display.getDefault().syncExec( new Runnable() { ... } );

or:

Display.getDefault().asyncExec( new Runnable() { ... } );

Upvotes: 2

Related Questions