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 / January 2005

Tip: Looking for answers? Try searching our database.

Setting a Dialog's owner after construction

Thread view: 
laura p - 26 Jan 2005 17:34 GMT
Hi,

I have a problem where I need to set the owner of a dialog after it has
been constructed.  Looking at the API, it looks like the only place i
can set the owner is in the super(Frame owner) or super(Dialog owner)
constructors.

I have a collection of dialogs, which are created using simple
reflection (i.e. no constructors).  I don't necessarily know what the
parent window is at this point.  Once they have all been constructed, I
retrieve a handle to the window, and want to iterate through the
dialogs and somehow set their owner to be my window.

Setting the owner is key, as it prevents the dialogs going behind the
main window, and also provides a location reference.
Any advice would be great!
laura
John McGrath - 26 Jan 2005 20:26 GMT
> I have a problem where I need to set the owner of a dialog after it has
> been constructed.

Sorry - you can't do that.

Signature

Regards,

John McGrath

Thomas Weidenfeller - 27 Jan 2005 08:08 GMT
> I have a problem where I need to set the owner of a dialog after it has
> been constructed.  Looking at the API, it looks like the only place i
> can set the owner is in the super(Frame owner) or super(Dialog owner)
> constructors.

You can't do that, but ...

> I have a collection of dialogs, which are created using simple
> reflection (i.e. no constructors).  I don't necessarily know what the
> parent window is at this point.

So don't create the dialogs at this point. If you absolutely must
construct a dialog's contents at this point, just create a JPanels with
all your components. When it is time to display the window, create a
JDialog with the desired parent, add the JPanel as content pane, pack(),
setVisible(true), and be done.

>  Once they have all been constructed, I
> retrieve a handle to the window,

Why can't you first retrieve the reference (not "handle") to your
window? I would like to suggest that you rethink your application
architecture.

/Thomas
Signature

The comp.lang.java.gui FAQ:
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq

laura p - 27 Jan 2005 09:48 GMT
Thank you for your suggestions, unfortunately a significant
architecture rethink is not possible.

My main application window is created by an existing large-scale
application.  I am currently writing an additional component for this
application using JavaBeans and a third party library (which also uses
JavaBeans).  BeanContext membership requires a default constructor.
This is called when the Beans are created - each bean is then given the
opportunity to utilise a handle (or reference ;) to every other bean in
that context.  It is at this point that each dialog can discover what
its parent _should_ be, but I cannot set it at that point...

I did consider creating each component as a panel, then add it to a
dialog at a later point.  However, any component that wants to affect
the dialog through an action (or retrieve its infomative contents) has
to get the reference to the actual dialog when the beans are created,
so this is not possible.

If it isn't possible to set the owner once the dialog has been created,
I will need to look at other ways of achieving the effect of being
owned by the main window...

L
Symon - 28 Jan 2005 08:10 GMT
You can also use a little workaround to attach your dialog with the
first visible frame :

  private Frame findActiveFrame() {
    Frame[] frames = JFrame.getFrames();
    for (int i = 0; i < frames.length; i++) {
      if (frames[i].isVisible()) {
        return frames[i];
      }
    }
    return null;
  }

And create your dialog with : new JDialog(findActiveFrame());

Hope this helps.

> Thank you for your suggestions, unfortunately a significant
> architecture rethink is not possible.
[quoted text clipped - 19 lines]
>
> L


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.