看看 Vaadin 组件目录中的Css Grid Layout。
有一个演示here
它支持跨行和跨列,例如此示例来自使用 FluentGridLayout.withItemWithSize() 方法的演示:
public class FlexibleGridLayoutExample2 extends HorizontalLayout {
public FlexibleGridLayoutExample2() {
FlexibleGridLayout layout = new FlexibleGridLayout()
.withColumns(Repeat.RepeatMode.AUTO_FILL, new MinMax(new Length("190px"), new Flex(1)))
.withAutoRows(new Length("190px"))
.withItems(
new ExampleCard(), new ExampleCard())
.withItemWithSize(new ExampleCard(), 2, 2) // add item with a custom size (2 rows and 2 cols)
.withItems(
new ExampleCard(), new ExampleCard(), new ExampleCard(), new ExampleCard(), new ExampleCard(),
new ExampleCard(), new ExampleCard(), new ExampleCard(), new ExampleCard(), new ExampleCard(),
new ExampleCard(), new ExampleCard(), new ExampleCard(), new ExampleCard(), new ExampleCard(),
new ExampleCard(), new ExampleCard(), new ExampleCard()
)
.withPadding(true)
.withSpacing(true)
.withAutoFlow(GridLayoutComponent.AutoFlow.ROW_DENSE) // allow the item order to be changed to let elements fill empty spaces.
.withOverflow(GridLayoutComponent.Overflow.AUTO);
layout.setSizeFull();
setSizeFull();
add(layout);
}
}
您还可以使用 FluentGridLayout 指定单元格的开始和结束位置。 withRowAndColumn() 方法:
public class CssGridLayoutExample1 extends VerticalLayout {
public CssGridLayoutExample1() {
Component alignTestComponent = new ExampleCard();
FluentGridLayout layout = new FluentGridLayout()
.withTemplateRows(new Flex(1), new Flex(1), new Flex(1))
.withTemplateColumns(new Flex(1), new Flex(1), new Flex(1))
.withColumnAlign(alignTestComponent, GridLayoutComponent.ColumnAlign.END)
.withRowAlign(alignTestComponent, GridLayoutComponent.RowAlign.END)
.withRowAndColumn(alignTestComponent, 1, 1, 1, 3)
.withRowAndColumn(new ExampleCard(), 2, 1)
.withRowAndColumn(new ExampleCard(), 2, 2)
.withRowAndColumn(new ExampleCard(), 1, 3, 3, 3);
layout.setSizeFull();
setSizeFull();
add(layout);
}
}