Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / March 2007

Tip: Looking for answers? Try searching our database.

Get frame reference

Thread view: 
Tony B - 02 Mar 2007 15:25 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. 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
Andrew Thompson - 02 Mar 2007 16:21 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.
..
> 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


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.