0

We add a parent to a JDialog by invoking super class constructor i.e super(parent).

Now I want to know is there any way using which I can add a parent component after my component is created.

Logic I know:

public MyJDialog(JFrame frame){

super(frame);

}

what I want is

public JDialog(){

super();

}

void setParent(JFrame frame)
    {
    this.setParent(frame);//just an example, I am looking for an actual API
}
Onki
  • 1,879
  • 6
  • 38
  • 58
  • which JComponent do you mean? Not all classes which extends JComponent have super(parent). – Leet-Falcon Dec 01 '15 at 08:48
  • @Leet-Falcon : I edited the qsn – Onki Dec 01 '15 at 08:52
  • 1
    Most of the time it's the other way around. Parent is set by calling add(child) on the parent. So both sides know their relationship. Can you explain what you plan to do that way? – Jan Dec 01 '15 at 08:53
  • @Jan : yes, I know. But I am looking for any Dyanmic assignment of parent – Onki Dec 01 '15 at 08:57
  • @HimJEL this is almost non-sense to change parent for a Dialog. Dialog are intended for interaction about things that happens in some part of an application, this is why they are attached to some parent. There is an exception as you can declare no parent at all, which basically means that your Dialog is in use to all your application. – Jean-Baptiste Yunès Dec 01 '15 at 09:23
  • The "owner" of a `JDialog` represents important information used by the dialog to make decisions about modality and other "window" related functionality. I `JComponent` may have a parent, but the function requirements are different – MadProgrammer Dec 01 '15 at 09:48
  • @Jean-BaptisteYunès what makes sense for me need not to make sense for you. you should be sensible before commenting on some one others curosity – Onki Dec 01 '15 at 10:25
  • Sorry it is not a matter of me, but a matter of what a Dialog is for... You may desire to make it but it is not designed as such because Dialogs are not designed for such a use. – Jean-Baptiste Yunès Dec 01 '15 at 10:40

2 Answers2

0

For JDialog you can only set the owner while using the constructor.
If you pass a null as an owner to the constructor - then one is assigned for you.
After which, you can not change or re-set the owner.

Leet-Falcon
  • 2,107
  • 2
  • 15
  • 23
0

It seems there is no way to set it. The alternative ways are described in below qsn : Is there a way to change the owner of a JDialog?

Community
  • 1
  • 1
Onki
  • 1,879
  • 6
  • 38
  • 58