views:

408

answers:

2

I have a very specific problem, and I wanted to know if there is a way to change the owner of a JDialog (it can be set using the constructor). I suppose there is no "official" possibility (other than a hack), but I wanted to make sure I didn't miss something. Any ideas or hints on the topic would be helpful, thanks already...

+1  A: 

Only thing I can think of falls under unsafe hack (use reflection and alter the owner, but that could possibly change under different version of the JVM (even from the same vensor on the same platform)).

Perhaps a better question for you to ask is "this is what I am trying to do... do I really need to change the owner of the dialog or is there a better way"? I am trying to think of reasons to want to change the owner and I cannot come up with any...

TofuBeer
+2  A: 

If your question is about how to reuse dialogs during your application lifecycle, then a better way is to:

  1. define all your dialog contents as JPanel subclasses
  2. and instantiate a new JDialog with the existing JPanel subclass instance

For point 2, you can of course use lazy evaluation of the panels (instantiate upon first use only, then reuse).

You will also need to have your panels implement some interface (of your own) that allows you to re-initialize them for reuse in a new JDialog (reinit typically means erasing all fields contents, or setting these fields back to their default values).

jfpoilpret