How to remove all components from a JFrame in Java?

自闭症网瘾萝莉.ら 提交于 2019-11-28 06:48:34
Kavka

You must call

 private JFrame frame = new JFrame();
 ...
 ...
 frame.getContentPane().removeAll();
 frame.repaint();

removeAll() has not been overridden as add() or remove() to forward to the contentPane as necessary.

Md Salman Ahmed
getContentPane().removeAll();
getContentPane().repaint();

assuming your goal is to add something else after you clear the frame you should call validate after adding thoes components to update it

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