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.
Strange behaviour with dynamic tree
Hi!
I am trying to implement a "lazy-tree" but have an extrage behaviour. Whe I first instantiate the windows it show the tree without the expand/collapse icon. If I close an reopen the same window it show it correctly but the same behaviour happend with the childrens that are showed whithout the icon, and are fixed when you close and open again only the items was expanded.
Here is my class:
public class RubrosTree extends CCTree {
private final static Logger LOGGER = Logger.getLogger(RubrosTree.class.getName());
ActivatableArrayList<Rubro> rubros;
public RubrosTree(ActivatableArrayList<Rubro> rr) {
this.rubros = rr;
this.init();
}
public RubrosTree(String caption, ActivatableArrayList<Rubro> rr) {
super(caption);
this.rubros = rr;
this.init();
}
private void init() {
LOGGER.log(Level.INFO, "inicializando el árbol...");
// recorrer el vector en forma recursiva agregando
for (Iterator<Rubro> it = rubros.iterator(); it.hasNext();) {
Rubro rubro = it.next();
this.addItem(rubro);
if (rubro.isLeaf()) {
LOGGER.log(Level.INFO, "hoja - rubro: {0}", rubro.toString());
this.setChildrenAllowed(rubro, false);
} else {
this.setChildrenAllowed(rubro, true);
}
}
this.addListener(new ExpandListener() {
private static final long serialVersionUID = 7555216006146778964L;
// cargar los nodos correspondientes
public void nodeExpand(ExpandEvent event) {
Rubro padre = (Rubro) event.getItemId();
LOGGER.log(Level.INFO, "Expandir Nodo: {0} - hijos: {1}", new Object[]{padre.toString(), padre.getSubrubrosCount()});
// buscar los hijos solo si no han sido incorporados previamente
if (getChildren(event.getItemId()) == null) {
LOGGER.log(Level.INFO, "incorporando hijos...");
for (int i = 0; i < padre.getSubrubrosCount(); i++) {
try {
Rubro r = padre.getSubrubro(i);
addItem(r);
setParent(r, padre);
if (r.isLeaf()) {
setChildrenAllowed(r, false);
} else {
setChildrenAllowed(r, true);
}
} catch (SubrubroIndexException ex) {
Logger.getLogger(RubrosTree.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
});
this.setImmediate(true);
}
}
The CCTree class only extends Tree. The objects have a collections with his childrens and you can get it with the getSubrubro(i).
I attached 4 png with the image that shown what happend.
Thanks!
Marcelo
--