Display open nodes in the GWT tree

I am creating a GWT tree and I would like it to initially display with open nodes. Take the standard tree example from GWT javadocs :

public class TreeExample implements EntryPoint {

  public void onModuleLoad() {
    // Create a tree with a few items in it.
    TreeItem root = new TreeItem("root");
    root.addItem("item0");
    root.addItem("item1");
    root.addItem("item2");

    // Add a CheckBox to the tree
    TreeItem item = new TreeItem(new CheckBox("item3"));
    root.addItem(item);

    Tree t = new Tree();
    t.addItem(root);

    // Add it to the root panel.
    RootPanel.get().add(t);
  }
}

I want it to initially display as:

root
  item0
  item1
  item2
  item3

Now I thought it was as simple as setting the state TreeItemI want to open by calling setState(true): javadoc for setStatesays: "Sets whether the children of this element are displayed." However, if you add, for example,

root.setState(true);

to the example above, I am not getting the expected effect. Apparently, nothing changes when I do root.setState(true);or root.setState(false);: the tree is always displayed with the nodes closed.

How do I get the desired behavior?

+3
1

setState() TreeItem Tree ( ).

, setState(true) TreeItem Tree.

+2

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


All Articles