更新面板 [英] updating a panel
本文介绍了更新面板的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的框架上有一个面板.单击一个按钮,我想删除旧面板并制作另一个面板,然后将该面板添加到我的框架中.(我也使用netbeans) 您能帮我个忙吗?谢谢
I have a panel on my frame .and by clicking on a button I want to delete the old panel and make the other panel and add that panel to my frame.(also I use netbeans) would you please help me that how can i do that?thanks
推荐答案
JFrame frame = new JFrame();
final JPanel origPanel = new JPanel();
frame.add(origPanel, BorderLayout.CENTER);
MouseListener ml = new MouseAdapter() {
public void mouseClicked(MouseEvent evt) {
// Mouse clicked on panel so remove existing panel and add a new one.
frame.remove(origPanel);
frame.add(createNewPanel(), BorderLayout.CENTER);
// Revalidate frame to cause it to layout the new panel correctly.
frame.revalidate();
// Stop listening to origPanel (prevent dangling reference).
origPanel.removeMouseListener(this);
}
}
origPanel.addMouseListener(ml);
这篇关于更新面板的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文