Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Tree: removing child nodes of a parent
I'm new to vaadin and I'm looking for a way to remove all the child nodes. I tried
@Override
public void nodeCollapse(CollapseEvent event) {
Object o=event.getItemId();
Collection<?> col=tree.getChildren(o);
col.clear();
}
and received an UnsupportedOperationException.
I tried using an Iterator and removing one at a time and also received an error. I looked through the forums and couldn't find the answer. Anyone have a solution to this?
Thanks in advance.
Hi,
If you are using Java 8, you can try something like:
Collection<?> childrenIDs = tree.getChildren(o);
childrenIDs.stream().forEach(tree::removeItem);
If not, maybe something like:
Object[] toRemove = childrenIDs.toArray();
int size = toRemove.length;
for (int i = 0; i < size; i++) {
tree.removeItem(toRemove[i]);
}
Hope that helps!