Reputation:
I have created a class which extends JFrame
public class MyFrame extends JFrame
{
public MyFrame()
{
JPanel panel = new JPanel();
JPanel panel2 = new JPanel();
JDialog myDialog = new JDialog(MyFrame, Dialog.ModalityType.DOCUMENT_MODAL);
//How can I set my MyFrame as Parent for JDialog???
panel.add(panel2);
add(panel);
}
}
In above code I want to set MyFrame as JDialog's parent. How can I do so? I tried putting like as I have shown in my code but that gives me error.
How can I set my MyFrame as Parent for JDialog???
Upvotes: 0
Views: 241
Reputation: 42176
You use the this keyword.
JDialog myDialog = new JDialog(this, Dialog.ModalityType.DOCUMENT_MODAL);
More info here: http://docs.oracle.com/javase/tutorial/java/javaOO/thiskey.html
Side note: You shouldn't extend JFrame for no reason. You should favor composition over inheritence. More info here and here.
Upvotes: 1