Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #1083 > unrolled thread

Get frame reference

Started by"Tony B" <tony.b@THRWHITE.remove-dii-this>
First post2011-04-27 15:31 +0000
Last post2011-04-27 15:31 +0000
Articles 5 — 4 participants

Back to article view | Back to comp.lang.java.gui


Contents

  Get frame reference "Tony B" <tony.b@THRWHITE.remove-dii-this> - 2011-04-27 15:31 +0000
    Re: Get frame reference "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:31 +0000
      Re: Get frame reference "Rogan Dawes" <rogan.dawes@THRWHITE.remove-dii-this> - 2011-04-27 15:31 +0000
        Re: Get frame reference "Tony B" <tony.b@THRWHITE.remove-dii-this> - 2011-04-27 15:31 +0000
        Re: Get frame reference "Michael Rauscher" <michael.rauscher@THRWHITE.remove-dii-this> - 2011-04-27 15:31 +0000

#1083 — Get frame reference

From"Tony B" <tony.b@THRWHITE.remove-dii-this>
Date2011-04-27 15:31 +0000
SubjectGet frame reference
Message-ID<8mXFh.90477$ff2.80185@fe02.news.easynews.com>
  To: comp.lang.java.gui
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. If I use this 
component with a null parent component the message box is displayed in the 
centre of the screen, which is correct but not what I want.

Ideally what I'm trying to do is identify the parentComponent for the main 
gui application so that I can display the dialog relative tothe application 
window ? Is this possible ?
Tony

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [next] | [standalone]


#1084

From"Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this>
Date2011-04-27 15:31 +0000
Message-ID<1172852502.858571.321180@8g2000cwh.googlegroups.com>
In reply to#1083
  To: comp.lang.java.gui
On Mar 3, 2:25 am, "Tony B" <tag...@yahoo.co.uk> wrote:
> 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.

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#1085

From"Rogan Dawes" <rogan.dawes@THRWHITE.remove-dii-this>
Date2011-04-27 15:31 +0000
Message-ID<es9jl8$2nt$1@wblv-ip-nnrp-1.saix.net>
In reply to#1084
  To: comp.lang.java.gui
Andrew Thompson wrote:
> On Mar 3, 2:25 am, "Tony B" <tag...@yahoo.co.uk> wrote:
>> 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.
> 

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

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#1086

From"Tony B" <tony.b@THRWHITE.remove-dii-this>
Date2011-04-27 15:31 +0000
Message-ID<a3ZFh.75164$gM1.47086@fe04.news.easynews.com>
In reply to#1085
  To: comp.lang.java.gui
"Rogan Dawes" <discard@dawes.za.net> wrote in message 
news:es9jl8$2nt$1@wblv-ip-nnrp-1.saix.net...
> Andrew Thompson wrote:
>> On Mar 3, 2:25 am, "Tony B" <tag...@yahoo.co.uk> wrote:
>>> 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.
>>
>
> 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

That seems to work fine.
Thanks
Tony

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [next] | [standalone]


#1089

From"Michael Rauscher" <michael.rauscher@THRWHITE.remove-dii-this>
Date2011-04-27 15:31 +0000
Message-ID<esaa04$m4d$1@registered.motzarella.org>
In reply to#1085
  To: comp.lang.java.gui
Rogan Dawes wrote:
> Andrew Thompson wrote:
>> 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

---
 * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.java.gui


csiph-web