Removing items in a container

When I try to remove components from the container, I use this code.

private static void clear(){
    for (int i = con.getComponentCount() - 1; i >= 1; i--){
        con.remove(i);
    }
}

When I call this function, the function acts as if it weren’t doing anything, but resets it as if it was overloaded. This does not give any errors. But when I paste con.getComponent(i).setVisible(false);into the code, it works, but I want to DELETE the components. Halp?

+3
source share
4 answers

After you finish removing the components you want to remove, call Container.validate (); Container.repaint (); In fact, you might want to repeat the test more than that.

+2
source

Try using this:

while (con.getComponentCount()>0) {
    con.remove(0);
}
+3
source

containerObject.repaint() ?

+1

, con awt,

con.removeAll();

.

0

All Articles