Differences
This shows you the differences between two versions of the page.
ui_access_from_job [2013/12/02 21:02] |
ui_access_from_job [2021/04/05 11:23] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Accessing UI from Background Job ====== | ||
+ | In SWT (Eclipse) the UI can only be access and modified from the main Thread. Everything else results in an error: | ||
+ | org.eclipse.swt.SWTException: | ||
+ | | ||
+ | This can be fixed by synchronizing the with the main thread. | ||
+ | |||
+ | In Eclipse e4 a '' | ||
+ | |||
+ | @Inject private UISynchronize sync; | ||
+ | | ||
+ | This allows us to run something from a background job accessing the UI. | ||
+ | |||
+ | <sxh java> | ||
+ | sync.asyncExec(new Runnable() { | ||
+ | |||
+ | @Override | ||
+ | public void run() { | ||
+ | // your UI access here | ||
+ | } | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | ===== Links ===== | ||
+ | * [[http:// | ||
+ | |||
+ | {{tag>e4 devel java}} |