当我最小化框架时面板组件消失 [英] Panel components disappear when I minimize frame
本文介绍了当我最小化框架时面板组件消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带有主面板的布局,其内容由我通过按钮通过以下方式确定:
I have a layout with a main panel whose content is decided by me throught buttons in this way:
public void actionPerformed(ActionEvent e) {
mainPanel.removeAll(); //removing all current panel components
if(e.getActionCommand().equals("content1")){
mainPanel = new Content1Panel();
add(mainPanel,BorderLayout.CENTER);
validate();
}else if(e.getActionCommand().equals("content2")){
mainPanel = new Content2Panel();
add(mainPanel,BorderLayout.CENTER);
validate();
}
}
现在,如果我最小化框架,然后将其放到最前面,我发现所有主面板的组件都消失了!无论如何,当我将鼠标悬停在它们上面时,鼠标组件再次显示出来. 怎么了?
now, if I minimize the frame and then bring it to front I find all main panel's components disappeared! Anyway, when I hover on them with the mouse components show again. What is wrong?
推荐答案
- 用于
JFrame
/JDialog
/JWindow
- for
JFrame
/JDialog
/JWindow
使用
validate(); (revalidate in Java7 )
repaint();
-
使用
CardLayout
而不是remove
,然后使用add
JPanel
到容器中use
CardLayout
instead ofremove
and thenadd
theJPanel
to the container这篇关于当我最小化框架时面板组件消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文