Class GridLayout
- All Implemented Interfaces:
Serializable, CssEmittingLayoutManager, LayoutManager
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:
-
Constructor Summary
ConstructorsConstructorDescriptionJDK:GridLayout()→ one row, columns derived from child count.GridLayout(int rows, int cols) GridLayout(int rows, int cols, int hgap, int vgap) -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLayoutComponent(String name, Component comp) Per-child CSS for onechildofparent;null(the default) means the child needs none.containerCss(Container parent) Container-wide CSS forparent's peer content element (its<div>).intintgetHgap()intgetRows()intgetVgap()minimumLayoutSize(Container parent) preferredLayoutSize(Container parent) voidvoidsetColumns(int cols) voidsetHgap(int hgap) voidsetRows(int rows) voidsetVgap(int vgap) toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface CssEmittingLayoutManager
cssLayoutName, layoutContainer
-
Constructor Details
-
GridLayout
public GridLayout()JDK:GridLayout()→ one row, columns derived from child count. -
GridLayout
public GridLayout(int rows, int cols) -
GridLayout
public GridLayout(int rows, int cols, int hgap, int vgap)
-
-
Method Details
-
getRows
public int getRows() -
setRows
public void setRows(int rows) -
getColumns
public int getColumns() -
setColumns
public void setColumns(int cols) -
getHgap
public int getHgap() -
setHgap
public void setHgap(int hgap) -
getVgap
public int getVgap() -
setVgap
public void setVgap(int vgap) -
addLayoutComponent
- Specified by:
addLayoutComponentin interfaceLayoutManager
-
removeLayoutComponent
- Specified by:
removeLayoutComponentin interfaceLayoutManager
-
preferredLayoutSize
- Specified by:
preferredLayoutSizein interfaceLayoutManager
-
minimumLayoutSize
- Specified by:
minimumLayoutSizein interfaceLayoutManager
-
childCss
Description copied from interface:CssEmittingLayoutManagerPer-child CSS for onechildofparent;null(the default) means the child needs none. Called once per child per pass, afterCssEmittingLayoutManager.containerCss(Container)(see the call-order contract).- Specified by:
childCssin interfaceCssEmittingLayoutManager
-
containerCss
Description copied from interface:CssEmittingLayoutManagerContainer-wide CSS forparent's peer content element (its<div>).- Specified by:
containerCssin interfaceCssEmittingLayoutManager- Returns:
- property→value map; a
nullvalue removes the property, an absent key is left untouched.
-
toString
-