> In a simple gui application, I'm writing some code in which I'm using
> JOptionPane to display messages in various parts of the code.
..
> Ideally what I'm trying to do is identify the parentComponent for the main
> gui application
..
> window ? Is this possible ?
Component has a getParent() method.
Keep calling that in a loop till the
call returns a null component, and you
should have the root component.
Andrew T.
Rogan Dawes - 02 Mar 2007 16:33 GMT
>> In a simple gui application, I'm writing some code in which I'm using
>> JOptionPane to display messages in various parts of the code.
[quoted text clipped - 10 lines]
>
> Andrew T.
And SwingUtilities has a method that will do this for you:
Window getWindowAncestor(Component c)
or
Window windowForComponent(Component c)
(not sure about the difference between these 2)
Rogan
Tony B - 02 Mar 2007 17:22 GMT
>>> In a simple gui application, I'm writing some code in which I'm using
>>> JOptionPane to display messages in various parts of the code.
[quoted text clipped - 23 lines]
>
> Rogan
That seems to work fine.
Thanks
Tony
Michael Rauscher - 02 Mar 2007 22:54 GMT
>> Component has a getParent() method.
>> Keep calling that in a loop till the
>> call returns a null component, and you
>> should have the root component.
>>
> And SwingUtilities has a method that will do this for you:
No. windowForComponent just calls getWindowAncestor. And
getWindowAncestor returns the *first* Window ancestor of a given
component. Andrew's method returns the *last* Component ancestor (which
might be a Window).
To get the root Window (or root Applet) of a component,
SwingUtilities#getRoot may be used. To get the root Component of a
component use Andrew's method. To get a component's window use
windowForComponent (or getWindowAncestor).
Of course, there might be additional predefined methods - who knows? ;)
Bye
Michael