Update customcomponent?


create an custom component, when I add another custom component via CustomComponent#addComponent(component, location), it works fine. But how can I remove components? I tried this:

                           Iterator<Component> iterator = mainLayout.getComponentIterator();
               while (iterator.hasNext()) {
		Component c = (Component) iterator.next();
		if(c == panel){

So when the component is removed, how should I update the mainLayout?

best regards,


Why don’t you just use: mainLayout.removeComponent(panel)

The component iterator should not be used to remove components, but you should always use removeComponent(…) or removeAllComponents(). Unfortunately this does not seem to be documented for ComponentContainer.getComponentIterator() javadoc, not for HasComponents.iterator() that replaces it.

For some component containers, a read-only iterator or an iterator to a copy of the original list is created, but for others that is not the case.

See also ticket