Vaadin - How to add a checkbox element to a tree?

I am using Vaadin 7.5.3 to develop a web application. There I need a tree with selectable nodes. I want to select nodes using checkboxes. Having tried many ways and points, I could not find how to add the CheckBox component to the node tree.

+4
source share
2 answers

As far as I know, until the current latest version of aka Vaadin 7.5.6 this is not possible, since Jouni points to this discussion of their forums . He also opened a ticket for improvement , but so far I do not see any changes.

, , 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

+2

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


All Articles