1. Error description
Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
at java.awt.Container.checkNotAWindow(Container.java:490)
at java.awt.Container.addImpl(Container.java:1091)
at java.awt.Container.add(Container.java:1005)
at javax.swing.JFrame.addImpl(JFrame.java:567)
at java.awt.Container.add(Container.java:417)
at com.you.cmdp.frame.CheckBox.(CheckBox.java:42)
at com.you.cmdp.frame.CheckBox.main(CheckBox.java:62)
2. The reason for the error
public CheckBox()
{
frame.setBounds(100, 100, 400, 300);
frame.setFont(font);
frame.setForeground(Color.WHITE);
frame.setBackground(Color.BLACK);
add(frame);
cbOne.setText("Section 1");
cbTwo.setText("Section 2");
cbThree.setText("Section 3");
cbFour.setText("Section 4");
panel.add(cbOne);
panel.add(cbTwo);
panel.add(cbThree);
panel.add(cbFour);
frame.add(panel);
}
In the constructor, JFrame is inherited, but add(frame) will not be added again
3. Solution
public CheckBox()
{
frame.setBounds(100, 100, 400, 300);
frame.setFont(font);
frame.setForeground(Color.WHITE);
frame.setBackground(Color.BLACK);
//add(frame);
cbOne.setText("Section 1");
cbTwo.setText("Section 2");
cbThree.setText("Section 3");
cbFour.setText("Section 4");
panel.add(cbOne);
panel.add(cbTwo);
panel.add(cbThree);
panel.add(cbFour);
frame.add(panel);
}
Read More:
- [Solved] JPA sett in parameter error: Java.lang.illegalargumentexception
- [Solved] Java.lang.ClassCastException: [Ljava.lang.Long; cannot be cast to java.util.List
- [Solved] ERROR SparkContext: Error initializing SparkContext. java.lang.IllegalArgumentException: System memo
- [Solved] Hibernate Error: java.lang.StackOverflowError at java.lang.Integer.toString(Integer.java:402)
- [Solved] nacos Startup Error: nested exception is java.lang.RuntimeException: java.lang.RuntimeException: [db-load-error
- Java uses class array to report error Exception in thread “main” java.lang.NullPointerException solution
- [Solved] Failed to convert value of type ‘java.lang.String‘ to required type ‘java.util.Date‘;
- [Solved] JAVA OpenCV Startup Error: java.lang.UnsatisfiedLinkError
- [Solved] java Internal error in the mapping processor java.lang.NullPointerException
- [Solved] java Internal error in the mapping processor java.lang.NullPointerException
- [Solved] java: Internal error in the mapping processor: java.lang.NullPointerException
- [Solved] JAVA Project Import jstl Error: java.lang.NoClassDefFoundError: javax/servlet/jsp/tagext/TagLibraryValidator
- JAVA error: java.lang.OutOfMemoryError:GC overhead limit exceeded
- [Solved] JAVA fx Error: java.lang.instrument ASSERTION FAILED ***: “!errorOutstanding“ with message transform
- [Solved] Hbase-shell 2.x Error: Unhandled Java exception: java.lang.IncompatibleClassChangeError: Found class jline.Terminal…
- [Solved] Java 9 reflection error: java.lang.reflect.InaccessibleObjectException
- [Solved] IDEA springboot Startup Error: java.lang.UnsatisfiedLinkError: no tcnative-1 in java.library.path
- java: java.lang.IllegalAccessError: class lombok.javac.apt.LombokProcessor (in unnamed module @0x590
- [Solved] Failed to start bean ‘eurekaAutoServiceRegistration‘; nested exception is java.lang.NullPointerExce
- Caused by: java.lang.IllegalStateException (How to Fix)