Java Error: IllegalArgumentException: adding a window to a container

后端 未结 3 581
温柔的废话
温柔的废话 2021-01-12 06:49

I keep receiving the error:

Exception in thread \"main\" java.lang.IllegalArgumentException: adding a window to a container
  at java.awt.Container.checkNotA         


        
相关标签:
3条回答
  • 2021-01-12 07:41

    EmployeeGUI extends from JFrame, but in your main method, you are creating a new JFrame and are trying to add an instance of EmployeeGUI to it.

    Change EmployeeGUI so it extends from JPanel instead

    0 讨论(0)
  • 2021-01-12 07:44

    Here:

    frame.getContentPane().add(app, BorderLayout.CENTER);
    

    you're trying to add a JFrame to a JFrame which makes no sense.

    Why not instead just try to display app rather than add it to a JFrame. Or even better, not have EmployeeGUI extend JFrame.

    0 讨论(0)
  • 2021-01-12 07:47

    You can't add a JFrame to another JFrame. But you can add a JPanel to a JFrame, in other words change EmployeeGUI to make it extends JPanel.

    0 讨论(0)
提交回复
热议问题