Java Error: IllegalArgumentException: adding a window to a container

混江龙づ霸主 提交于 2019-12-01 06:12:25

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

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.

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!