Panel components disappear when I minimize frame

2019-06-28 05:23发布

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?

1条回答
小情绪 Triste *
2楼-- · 2019-06-28 05:45
  • for JFrame / JDialog / JWindow

to use

validate(); (revalidate in Java7 )
repaint();
查看更多
登录 后发表回答