我正在使用Vaadin 7.5.3开发Web应用程序。在这里,我需要一个具有可选节点的树形结构。我想使用复选框来选择节点。尝试了许多方法和搜索,但我无法找到如何将CheckBox组件添加到树节点中。
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());
这是输出结果
这是一个旧问题,但值得一提的是:Vaadin演示页面中有一个完全符合此要求的示例:
http://demo.vaadin.com/book-examples/book#component.tree.itemstylegenerato
tree.setReadOnly(false)
吗? - S.M.Amin