Class BoxLayout

java.lang.Object
vaadinx.swing.BoxLayout
All Implemented Interfaces:
Serializable, CssEmittingLayoutManager, LayoutManager, LayoutManager2

public class BoxLayout extends Object implements LayoutManager2, CssEmittingLayoutManager, Serializable
Emulator for BoxLayout. Joins FlowLayout / BorderLayout as the third built-in layout manager. Under D_layout_css_on_content, LayoutManager.layoutContainer(Container) writes display: flex; flex-direction: row|column 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. Lives in vaadinx.swing (not vaadinx.awt) because the JDK class is javax.swing.BoxLayout, not java.awt.BoxLayout.

RTL caveat. JDK BoxLayout flips LINE_AXIS between row and row-reverse based on the container's ComponentOrientation; PAGE_AXIS flips for vertical-text orientations. CSS flex-direction isn't orientation-aware, and tracking orientation at layoutContainer time would require rebuilding the dispatch path. We pin the LTR mapping (X_AXIS/LINE_AXIS → row, Y_AXIS/PAGE_AXIS → column) per R_layouts_close_enough — same shape as BorderLayout's LINE_START/LINE_END caveat.

Per-child sizing. JDK BoxLayout reads each child's getMinimumSize / getPreferredSize / getMaximumSize and getAlignmentX / getAlignmentY to distribute space. Vaadin's flex defaults (flex: 0 0 auto) give children their intrinsic content size with no growth — close-enough for the canonical Swing pattern (vertical row stack with Box.createVerticalStrut(int) / Box.createVerticalGlue() carrying spacing and expansion). Setting Component.alignmentX/Y doesn't write a per-child align-self today: JComponent.setAlignmentX/Y is onNoop and the getters always return 0.5f, so any write would be align-self: center — flex's default, so adds DOM noise with zero information. R_layouts_close_enough; revisit when alignment becomes a stored property.

Bound to one container. Like JDK BoxLayout, instances are tied to the Container passed at construction time: invalidateLayout(Container) (and LayoutManager.layoutContainer(Container)) throw AWTError when called with a different container, matching Swing per R_match_swing_errors.

See Also: