开发者

display open nodes in a GWT Tree

开发者 https://www.devze.com 2023-01-20 15:57 出处:网络
I create a GWT Tree, and I would like it to be initially displayed with open nodes. Let\'s take the standard Tree example from GWT javadocs:开发者_Python百科

I create a GWT Tree, and I would like it to be initially displayed with open nodes. Let's take the standard Tree example from GWT javadocs:开发者_Python百科

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 initially displayed as:

root
  item0
  item1
  item2
  item3

Now, I thought that it was as simple as setting the state of the TreeItem that I want to be opened by calling setState(true): javadoc for setState says "Sets whether this item's children are displayed". However, if I add for example

root.setState(true);

to the above example, I don't get the expected effect. Apparently nothing changes when I do root.setState(true); or root.setState(false);: the tree is always displayed with its nodes closed.

How do I get the desired behaviour?


The call to setState() depends on the sequence of the method calls to TreeItem and Tree (as stated here).

As a rule of thumb call setState(true) after adding all the items to the TreeItem and after adding the root item to the Tree.

0

精彩评论

暂无评论...
验证码 换一张
取 消