用baidu搜了半天搜不出来,用google一下就出来了~~~
下面用自己的代码来解释下removeAll()的用法
注意一定要在getContentPane()中用removeAll();
import javax.swing.JButton;
import javax.swing.JFrame;
public class Main extends JFrame{
private static final long serialVersionUID = 1L;
public JButton JJ=new JButton("fdsafd");
Main(){
this.setVisible(true);
}
public void add(){
this.add(JJ);
this.pack();
}
public void delete(){
removeAll();
}
}
import java.awt.FlowLayout;
public class Case {
public static void main(String args[]){
Main a=new Main();
a.add();
a.setLayout(new FlowLayout()); //removeAll()不移除布局格式。
a.getContentPane().removeAll(); //注意一定要在getContentPane()中用removeAll();
a.add();
a.setBounds(10, 10, 200, 210);
}
}