|
Re: Finding the right parent for a SWT Shell [message #463119 is a reply to message #463118] |
Wed, 26 October 2005 22:53 |
Eclipse User |
|
|
|
Originally posted by: richkulp.us.NO_SPAM.ibm.com
You can do widget stuff only on the UI thread. So that is why it failed.
You need to be on the UI thread to do a Shell create.
By the way, the display is not the parent of the shell, it is the
display for the shell. Parent is only used in dialogs so that the shell
(dialog) will always stay in front of the parent.
There are three ways to get the display if you are not on the display
thread. One is you have it somewhere, or you have access to another
widget that you want to be on the same display as. You can then ask the
widget for its display.
The third way is to always use the default display.
Either way you then need to use display.asyncExec(runnable) to actually
create your shell on that display. (or syncExec(runnable) if you need to
wait for the runnable to complete so that you can get some info back
from it, such as the shell that you created).
Mike Greenawalt wrote:
> Hi -
>
> I am developing some code in Eclipse. I want to open a window and display
> some data to the user. My problem is -- how do I determine the right parent
> for the window? Every SWT control needs a parent to be specified to its
> constructor, and I do not have a handle to the graphic environment of
> Eclipse at the point I want to display the data.
>
> According to what I read about SWT, one cannot just create a new Display
> object -- there is supposed to only be one in effect at a time. So, I must
> use the existing Display as the parent of the Shell that I want to open.
>
> Display.getCurrent() returns null, which means that my code is not running
> in the ui thread. That is probably true.
>
> Display.getDefault() returns a Display object, but when trying to create a
> Shell with it as parent, the code throws a SWTException, Invalid thread
> access, which means the current thread is not the thread that created the
> object.
>
> Any advice would be very much appreciated.
>
> -- Mike
>
>
--
Thanks,
Rich Kulp
|
|
|
|
Powered by
FUDForum. Page generated in 0.03155 seconds