JFrame frame1 = new JFrame("frame");
frame1.setVisible(true);
frame1.setPreferredSize(new Dimension(800, 600));
frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel Panel1 = new JPanel();
JPanel Panel2 = new JPanel();
frame1.add(Panel1,BorderLayout.SOUTH);
frame1.add(Panel2,BorderLayout.North);
我怎麼做這樣的事,如果有事的框架是空白刪除的JFrame面板
if(SOMETHINGHAPPENS)
{
//remove all panels from frame 1 so i have a blank frame
//now i want to add some new panels
}
http://stackoverflow.com/questions/2501861/之間切換如何從j-frame中移除jpanel可能會有所幫助。換句話說,使用'frame1.remove()'。 –
@MadProgrammer謝謝。 Java 7,它確實:http://docs.oracle.com/javase/7/docs/api/javax/swing/JFrame.html#remove(java.awt.Component)雖然我不確定以前的版本。 –
@NicolásCarlo是的,它是'removeAll',做怪異的東西 – MadProgrammer