Java swing difference remove and removeAll -


what de difference between remove , removeall in java swing library? have 1 control panel , panel can changed control panel. changing done in parent frame object. when use code:

public void shownextpanel(){         if(hasnextpanel()){             getselectedpanel().setvisible(false);             getcontentpane().removeall();             getcontentpane().add(controlpanel);             selectedpanel++;             getcontentpane().add(getselectedpanel());             getselectedpanel().setvisible(true);             revalidate();             repaint();         }else{             system.exit(0);         }     } 

then works expected. when change removeall in remove statement, selected panel becomes gray, still visible. when resizing frame, new frame visible, can see hiding behind previous selected panel. code is:

public void shownextpanel(){         if(hasnextpanel()){             getselectedpanel().setvisible(false);             getcontentpane().remove(getselectedpanel());             selectedpanel++;             getcontentpane().add(getselectedpanel());             getselectedpanel().setvisible(true);             revalidate();             repaint();         }else{             system.exit(0);         }     } 

why jpanel disappear when using removeall not when using remove?

the method names big hint, , definitive answer in javadocs:

for container.remove(component):

"removes the specified component container."

for container.removeall():

"removes all components container."

as causing difference in behaviour, guess there other component in panel getting removed in first case, not in second case.

try calling , logging / printing getcomponentcount() after "remove" in both cases.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -