Using the ZK Tree component, how to remove Treeitems from a Treechildren node

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

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

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

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

Any ideas?

+3
source share
3 answers

This is not the right way to remove items, you need to do something like this.

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

This will provide the functionality you need!

More information on using the Tree component is available here.

+2
source

As I saw in your case, you want to remove all the components that are all attached to treechildren. I think the fastest way:

treechildren.getChildren().clear();

java.util.List.

0
Vbox hbC;

hbC.appendChild(hijo1);

hbC.appendChild(hijo2);

for(int i = 0; 
  i< hbC.getChildren().size(); i++){

            hbC.removeChild(hbC.getChildren().get(i));
        } 

optional

try{

if(hbC.getChildren().size()>0){

for (Component c : hbC.getChildren()) {

           hbC.removeChild(c);
}

}

 1. List item

}catch()
-1

Source: https://habr.com/ru/post/1721651/


All Articles