Today I wanted to create a layout like the HorizontalLayout, except that I wanted it to wrap.
When I googled this, I saw hints that a CssLayout was the way to go, but I found no concrete examples.
It is possible that this is common knowledge in the community, but in case there are others that are struggling with the same, here is how I solved it:
What stumped me was that the fields and their labels in a CssLayout are just a flat list of
It is possible that there is some css magic that can group these together in pairs and render them the way I want, but that was beyond me.
What I wanted was a parent
It finally dawned on me that a CssLayout
is
more or less only a
This worked like a charm.
CssLayout wrappingLayout = new CssLayout();
<parent>.addComponent(wrappingLayout);
wrappingLayout.setStyleName("wrap");
for(int i=0; i<20; i++) {
CssLayout slot = new CssLayout();
slot.setPrimaryStyleName("v-slot");
wrappingLayout.addComponent(slot);
Field f = new TextField("Textfield no " + i);
slot.addComponent(f);
}
And in my css, just to get some space between each slot:
.v-csslayout-wrap > .v-slot {
margin-right: 8px;
}