Exception : adding a window to a container. How to solve it?

血红的双手。 提交于 2019-11-29 15:20:47

What does this mean..

One top level container (dialog) cannot be added to another (frame).

..and how can i solve this ?

Just call setVisible(true) on the Preferences dialog, rather than adding it.

You don't add the JDialog to the JFrame, that makes no sense whatsoever since the add(...) method is for adding components to be displayed in the container, not by the container. You display the JDialog from the JFrame's JButton's ActionListener. You also shouldn't be mixing AWT (Frame) components and Swing components together for no good reason.

Your question suggests that you would benefit greatly by going through the Swing tutorials.

JDialog and JFrame are top-level container. I suggest that you should have to use JFrame, JInternalFrame and JDesktopPane.

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