Java Container remove method not working correctly

可紊 提交于 2019-11-27 05:39:08
trashgod

The Container returned by getContentPane() is, by default, the contentPane of a JRootPane managed by the top-level container, JFrame. Although, "as a convenience, the add method and its variants, remove and setLayout have been overridden to forward to the contentPane as necessary," there's no a priori way to know about the frame's internal use of component indices.

Instead, add on your own JComponent to the frame and operate on it; JPanel is a common choice.

Addendum: Also consider an alternative layout such as CardLayout, illustrated here.

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