Class GridLayout

java.lang.Object
vaadinx.awt.GridLayout
All Implemented Interfaces:
Serializable, CssEmittingLayoutManager, LayoutManager

public class GridLayout extends Object implements CssEmittingLayoutManager, Serializable
Emulator for GridLayout (D_gridlayout). Under D_layout_css_on_content, CssEmittingLayoutManager.layoutContainer(Container) writes display: grid; grid-template-columns: repeat(ncols, 1fr); grid-template-rows: repeat(nrows, 1fr); gap: … to the container's peer content element via EHelper.applyContainerCss(Element, String, Map).

Hand-written rather than generator-emitted: the generator's root-class detection assumes Component-hierarchy ancestry and would emit a peer field, which a LayoutManager doesn't have. Plain LayoutManager (not LayoutManager2) — JDK GridLayout has no per-child constraint storage; cell assignment is purely insertion-order driven, which the browser's grid auto-placement (row-major, the CSS default) reproduces exactly.

Dimension resolution. JDK GridLayout fixes one dimension and derives the other from the live component count: with rows > 0 the row count is authoritative and columns are ceil(n / rows); with rows == 0 columns are authoritative and rows are ceil(n / cols). That count isn't known until layout time, so — unlike the constraint-carrying GridBagLayout — this layout reads Container.getComponentCount() inside CssEmittingLayoutManager.layoutContainer(Container) and computes the resolved dimensions there, exactly as JDK's layoutContainer does.

Cell sizing (R_layouts_close_enough). Every cell is an equal fraction (1fr) and every child stretches to fill it (align/justify-items: stretch) — matching GridLayout's "all cells equal, components resized to fill" contract. We do not compute the pixel arithmetic JDK does from child preferred sizes; the browser divides the container evenly, which is close-enough per R_layouts_close_enough. hgap/vgap carry through to CSS gap.

See Also: