Vaadin - 如何将复选框组件添加到树形结构中?

5

我正在使用Vaadin 7.5.3开发Web应用程序。在这里,我需要一个具有可选节点的树形结构。我想使用复选框来选择节点。尝试了许多方法和搜索,但我无法找到如何将CheckBox组件添加到树节点中。


你目前进展如何?(你尝试过树形可编辑模式吗?) - André Schild
可编辑模式是什么意思?您是指 tree.setReadOnly(false) 吗? - S.M.Amin
2个回答

6
根据我的了解,截至目前最新版本Vaadin 7.5.6,这是不可能的,正如Jouni在他们论坛上的讨论中指出的那样。他也开了一个改进票,但我迄今没有看到任何变化。
尽管如此,您可以通过使用TreeTable组件来“伪造”它。您可以在这里找到一个完整的示例,并在下面找到其中的一部分:
final TreeTable ttable = new TreeTable("My TreeTable");
ttable.addContainerProperty("Name", CheckBox.class, "");
ttable.addContainerProperty("City", String.class, "");
ttable.setWidth("20em");

// Create the tree nodes
ttable.addItem(new Object[]{new CheckBox("Root"), "Helsinki"}, 0);
ttable.addItem(new Object[]{new CheckBox("Branch 1"), "Tampere"}, 1);
ttable.addItem(new Object[]{new CheckBox("Branch 2"), "Turku"}, 2);
ttable.addItem(new Object[]{new CheckBox("Leaf 1"), "Piikkiö"}, 3);
ttable.addItem(new Object[]{new CheckBox("Leaf 2"), "Parainen"}, 4);
ttable.addItem(new Object[]{new CheckBox("Leaf 3"), "Raisio"}, 5);
ttable.addItem(new Object[]{new CheckBox("Leaf 4"), "Naantali"}, 6);

// Set the hierarchy
ttable.setParent(1, 0);
ttable.setParent(2, 0);
ttable.setParent(3, 1);
ttable.setParent(4, 1);
ttable.setParent(5, 2);
ttable.setParent(6, 2);

// Expand the tree
ttable.setCollapsed(2, false);
for (Object itemId: ttable.getItemIds())
    ttable.setCollapsed(itemId, false);

ttable.setPageLength(ttable.size());

这是输出结果

checkbox in tree


1

https://github.com/vaadin/book-examples/blob/master/src/com/vaadin/book/examples/component/TreeExample.java - Alex78191
为什么不使用TreeGrid? - Alex78191
@Alex78191 那个时候那并不存在。 - geert3

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接