I have a JDialog
class named Preferences
. This class creates a constructor like:
class Preferences extends javax.swing.JDialog {
Preferences(java.awt.Frame parent,modal) {
super(parent,modal);
//......
}
}
In my program I want this preferences dialog to open up as I click a button from a JFrame
form. After I registered the action listener on the button, I wrote the code inside as:
Frame fr = new Frame();
Preferences p = new Preferences(fr,false);
fr.add(p);
fr.setVisible(true);
When I run this code I get the following exception (as I click the button):
Exception in thread "AWT-EventQueue-0"
java.lang.IllegalArgumentException: adding a window to a container
What does this mean and how can I solve it?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…