简体   繁体   中英

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?

  • for JFrame / JDialog / JWindow

to use

validate(); (revalidate in Java7 )
repaint();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM