Class GridBagLayout
- All Implemented Interfaces:
Serializable, CssEmittingLayoutManager, LayoutManager, LayoutManager2
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:
-
Field Summary
FieldsModifier and TypeFieldDescriptiondouble[]int[]protected GridBagConstraintsprotected static final intprotected static final intprotected static final intint[]double[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLayoutComponent(String name, Component comp) voidaddLayoutComponent(Component comp, Object constraints) 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>).getConstraints(Component comp) floatgetLayoutAlignmentX(Container target) floatgetLayoutAlignmentY(Container target) voidinvalidateLayout(Container target) maximumLayoutSize(Container target) minimumLayoutSize(Container parent) preferredLayoutSize(Container parent) voidvoidsetConstraints(Component comp, GridBagConstraints constraints) toString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface CssEmittingLayoutManager
cssLayoutName, layoutContainer
-
Field Details
-
MAXGRIDSIZE
protected static final int MAXGRIDSIZE- See Also:
-
MINSIZE
protected static final int MINSIZE- See Also:
-
PREFERREDSIZE
protected static final int PREFERREDSIZE- See Also:
-
defaultConstraints
-
columnWidths
public int[] columnWidths -
rowHeights
public int[] rowHeights -
columnWeights
public double[] columnWeights -
rowWeights
public double[] rowWeights
-
-
Constructor Details
-
GridBagLayout
public GridBagLayout()
-
-
Method Details
-
getConstraints
-
setConstraints
-
addLayoutComponent
- Specified by:
addLayoutComponentin interfaceLayoutManager
-
addLayoutComponent
- Specified by:
addLayoutComponentin interfaceLayoutManager2
-
removeLayoutComponent
- Specified by:
removeLayoutComponentin interfaceLayoutManager
-
preferredLayoutSize
- Specified by:
preferredLayoutSizein interfaceLayoutManager
-
minimumLayoutSize
- Specified by:
minimumLayoutSizein interfaceLayoutManager
-
maximumLayoutSize
- Specified by:
maximumLayoutSizein interfaceLayoutManager2
-
getLayoutAlignmentX
- Specified by:
getLayoutAlignmentXin interfaceLayoutManager2
-
getLayoutAlignmentY
- Specified by:
getLayoutAlignmentYin interfaceLayoutManager2
-
invalidateLayout
- Specified by:
invalidateLayoutin interfaceLayoutManager2
-
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.
-
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
-
toString
-