Class GridBagLayout

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

public class GridBagLayout extends Object implements LayoutManager2, CssEmittingLayoutManager, Serializable
Emulator for GridBagLayout. Under D_layout_css_on_content, LayoutManager.layoutContainer(Container) writes display: grid; grid-template-columns: …; grid-template-rows: … to the container's peer content element via EHelper.applyContainerCss(Element, String, Map), plus per-child grid-row/grid-column/justify-self/ align-self/margin/padding writes.

Hand-written rather than generator-emitted: same as FlowLayout / BorderLayout / BoxLayout — the generator's root-class detection assumes Component-hierarchy ancestry and would emit a peer field, which a LayoutManager doesn't have.

GridBagConstraints stays JDK per D_whitelist_porting's data-types-stay-JDK rule. Constraints are pure data carriers — no Component reference, no methods that touch the Component hierarchy. User code's GridBagConstraints.WEST/HORIZONTAL/etc. constants land from GridBagConstraints unchanged across the import swap. Insets likewise stays JDK.

CSS Grid mapping. Per-track sizing follows JDK GridBagLayout's "any non-zero weightx in a column makes that column absorb extra space" rule: aggregate per-column max weightx and per-row max weighty across all children, then map non-zero weights to minmax(0, Nfr) and zero weights to auto. The minmax(0, Nfr) (vs. plain Nfr) lets weighted tracks shrink below their content's intrinsic size when the grid container is height/width-bounded — same shape as BorderLayout's CENTER track.

RELATIVE / REMAINDER resolution. Constraints are cloned at addLayoutComponent(String, Component) time (matching JDK's Hashtable<Component, GridBagConstraints> semantics — user code that mutates the original GridBagConstraints after each add() relies on this), and RELATIVE/REMAINDER for gridx/gridy resolves immediately against the running cursor. RELATIVE for gridwidth/gridheight resolves at LayoutManager.layoutContainer(Container) time once the peak track count is known. Bucket 3 of D_gridbaglayout (multi-row REMAINDER cursor reset, RELATIVE chains beyond the canonical idioms) is deferred — drop-and-WARN on the configurations the cursor model can't resolve.

Anchor / fill mapping. All 13 absolute anchor constants (CENTER + 8 cardinals/corners + 4 baseline variants) map to (justify-self, align-self) pairs. Orientation-relative anchors (LINE_START / PAGE_START / FIRST_LINE_START / etc.) pin to the LTR mapping per R_layouts_close_enough — same caveat as BorderLayout's LINE_START/LINE_END and BoxLayout's LINE_AXIS/PAGE_AXIS. Baseline anchors collapse to top/center/bottom — CSS has no baseline-grid concept. fill (NONE/HORIZONTAL/VERTICAL/BOTH) overrides anchor on whichever axis it stretches.

Insets and ipadx/ipady. insets writes per-child margin (external spacing — matches JDK's "space around the component within its cell"). ipadx/ipady writes per-child padding (internal padding — matches JDK's "extra width/height added to the component's preferred size before layout"). Combined effect approximates JDK's pixel arithmetic to within R_layouts_close_enough.

See Also: