Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Finding the right parent for a SWT Shell
Finding the right parent for a SWT Shell [message #463118] Wed, 26 October 2005 22:46 Go to next message
Mike Greenawalt is currently offline Mike GreenawaltFriend
Messages: 50
Registered: July 2009
Member
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
Re: Finding the right parent for a SWT Shell [message #463119 is a reply to message #463118] Wed, 26 October 2005 22:53 Go to previous messageGo to next message
Eclipse UserFriend
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
Re: Finding the right parent for a SWT Shell [message #463130 is a reply to message #463119] Thu, 27 October 2005 14:17 Go to previous message
Douglas Pollock is currently offline Douglas PollockFriend
Messages: 84
Registered: July 2009
Member
Rich Kulp wrote:
> 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.

Just as an addendum to this. ProgressManagerUtil.getShellProvider() shows a
rather sophisticated (read: complex, complete, etc.) way of finding an
appropriate parent shell.



cheers,
d.
Previous Topic:[URG]
Next Topic:How to set input on browser widget synchronously?
Goto Forum:
  


Current Time: Sat Apr 20 00:45:21 GMT 2024

Powered by FUDForum. Page generated in 0.03155 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top