Package org.patternfly.layout
package org.patternfly.layout
PatternFly layouts provide structure and positioning for content on a page. They offer flexible, responsive
solutions for organizing UI elements and are designed to work seamlessly across different screen sizes and
breakpoints.
Available breakpoints:
Layouts supporting gutters:
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 fromBaseLayout, which implements common
interfaces from Elemento for element manipulation:
ElementAttributeMethodsElementClassListMethodsElementContainerMethodsHTMLElementStyleMethods- And more...
Responsive Design
Many layout properties support responsive values at different breakpoints using theBreakpoints API:
Flex flex = flex()
.direction(breakpoints(
default_, Direction.column,
md, Direction.row))
.spaceItems(breakpoints(
default_, SpaceItems.sm,
lg, SpaceItems.lg));
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 theGutter 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()));
- See Also:
-
ClassDescription