Package org.patternfly.layout
Available Layouts
This package provides the following layout types:
Bullseye- Centers content both vertically and horizontally within a container.
Flex- Provides a completely custom layout utilizing the PatternFly spacer and breakpoint systems. Supports adjustments to spacing, direction, alignment, justification, wrapping, and width.
Gallery- Arranges content in a responsive grid with uniform rows and columns that wrap automatically.
Grid- Places content on a fixed 12-column grid system.
Level- Distributes content evenly across a horizontal row.
Split- Distributes content horizontally with support for wrapping and spacing control.
Stack- Positions items vertically, with one or more items filling the available vertical space.
Common API Pattern
All layouts follow a consistent API design:
- Static factory methods - Create layout instances using static methods named after the layout
- Add methods - Add child items using
addItem()oraddItems()methods - Builder methods - Configure layout properties using fluent builder methods
- Responsive breakpoints - Many properties support responsive values at different breakpoints
Usage Examples
Bullseye Layout
Center content both vertically and horizontally:
Bullseye bullseye = bullseye()
.addItem(bullseyeItem()
.add(div().textContent("Centered content")));
Flex Layout
Create a flexible layout with custom spacing and alignment:
Flex flex = flex()
.direction(Direction.column)
.spaceItems(SpaceItems.md)
.addItem(flexItem().add(div().textContent("Item 1")))
.addItem(flexItem().add(div().textContent("Item 2")))
.addItem(flexItem().add(div().textContent("Item 3")));
Gallery Layout
Create a responsive grid of cards:
Gallery gallery = gallery()
.gutter()
.addItem(galleryItem().add(card()))
.addItem(galleryItem().add(card()))
.addItem(galleryItem().add(card()));
Grid Layout
Position content on a 12-column grid:
Grid grid = grid()
.gutter()
.addItem(gridItem().span(8).add(div().textContent("Main content")))
.addItem(gridItem().span(4).add(div().textContent("Sidebar")));
Stack Layout
Arrange items vertically:
Stack stack = stack()
.gutter()
.addItem(stackItem().add(div().textContent("Header")))
.addItem(stackItem().fill().add(div().textContent("Main content")))
.addItem(stackItem().add(div().textContent("Footer")));
Base Classes
All layouts extend from BaseLayout, which implements common
interfaces from Elemento for element manipulation:
ElementAttributeMethodsElementClassListMethodsElementContainerMethodsHTMLElementStyleMethods- And more...
This provides a rich set of methods to manipulate the layout's underlying DOM element.
Responsive Design
Many layout properties support responsive values at different breakpoints using the
Breakpoints API:
Flex flex = flex()
.direction(breakpoints(
default_, Direction.column,
md, Direction.row))
.spaceItems(breakpoints(
default_, SpaceItems.sm,
lg, SpaceItems.lg));
Available breakpoints:
default_- Default valuesm- Small screens (576px+)md- Medium screens (768px+)lg- Large screens (992px+)xl- Extra large screens (1200px+)_2xl- 2X large screens (1450px+)
Gutter Support
Several layouts implement the Gutter interface, which provides
methods to add spacing between child items:
Gallery gallery = gallery()
.gutter() // Enable gutter spacing
.addItem(galleryItem().add(card()))
.addItem(galleryItem().add(card()));
Layouts supporting gutters:
- See Also:
-
ClassDescriptionBase class for all PatternFly layout components, providing common layout behavior and OUIA support.Common interface implemented by all PatternFly layout components.Enumerates the available PatternFly layout types with their identifiers and OUIA names.Base class for layout sub-components such as items within a layout container.