Search code examples
treezk

Using ZK Tree component, how do I remove Treeitems from a Treechildren node


Does anyone know how to remove Treeitems from a Treechildren node in ZK? I have tried using an iterator and removeChild but a ConcurrentModificationException!

List<Treeitem> myTreeItems = treechildren.getChildren();

Iterator<Treeitem> iterator = myTreeItems.iterator();

while (iterator.hasNext()){
   myItem = (Treeitem)iterator.next();
   parent.removeChild(myItem);
}

Any ideas?


Solution

  • That is not the correct way to remove the items, you need to do something like this.

    while (parent.getItemCount() > 0) {
       parent.removeChild(parent.getFirstChild());
    }
    

    This will provide the functionality that you require!

    More details on using the Tree component are available here.