ColumnsLayout
The ColumnsLayout component arranges items into a responsive column-based layout that adjusts based on available width. Breakpoints and alignments are managed automatically, so building multi-column forms and content grids doesn't require custom responsive logic.
Default behavior
By default, a ColumnsLayout arranges items in two columns and takes the full width of its parent. The display can be further adjusted with breakpoints and alignment settings, covered in the sections below.
Show Code
- ColumnsLayoutView.java
This can be used in place of, or in combination with, the FlexLayout component - an equally powerful tool for horizontal layouts.
Breakpoints
At its core, the ColumnsLayout is designed to provide a fluid, grid-like system that adapts to the width of its parent container. Unlike traditional fixed-grid systems, this layout allows developers to specify a number of columns at a given width, and dynamically calculates the number of displayed columns based on set Breakpoint objects.
This allows a ColumnsLayout to smoothly adapt from a more constrained space on small screens to a wider area on larger screens, offering a responsive design to a developer without needing custom implementation.
Understanding a Breakpoint
A Breakpoint can be specified using the Breakpoint class, which takes three parameters:
-
Name (optional): Naming a breakpoint allows you to reference it in future configurations.
-
Minimum width: Each breakpoint has a specific range that determines when its layout is applied. The minimum width is defined explicitly, and the next breakpoint determines the maximum width if it exists. You can use an integer to define the minimum width in pixels or use a
Stringto specify other units such asvw,%, orem. -
Number of columns: Specify how many columns a breakpoint should have with this integer.
Breakpoint evaluationBreakpoints are evaluated in ascending order of the width, meaning the layout will use the first matching breakpoint.