Package org.patternfly.component
This package contains the core components of PatternFly Java, a 100% Java implementation of PatternFly design system without any JavaScript dependencies. It integrates with and builds upon Elemento's builder API and works with both GWT and J2CL.
Quick Start
Components are created using static factory methods and configured using a fluent builder API:import static org.patternfly.component.button.Button.button;
import static org.patternfly.component.alert.Alert.alert;
import static org.patternfly.component.card.Card.card;
Button btn = button("Click me!");
Alert alert = alert(info, "Info", "This is an information message");
Card card = card()
.flat()
.rounded()
.large();
API Design
The component API follows consistent patterns organized into these groups:Static Factory Methods
Create components using static factory methods named after the component. These methods are overloaded to accept required and optional arguments:Button button1 = button("Click me!");
Button button2 = button("PatternFly", "https://www.patternfly.org");
Add Methods
Add subcomponents usingadd<SubComponent>() methods that return the parent component
for method chaining:
Dropdown dropdown = dropdown()
.addToggle(menuToggle("Dropdown"))
.addMenu(menu()
.addContent(menuContent()
.addList(menuList()
.addItem(actionMenuItem("item-0", "Action")))));
Builder/Modifier Methods
Modify component appearance and behavior using chainable builder methods:Card card = card()
.flat()
.rounded()
.large();
Event Handlers
Register event handlers usingon<Event>() methods. PatternFly Java defines
common event handlers in org.patternfly.handler that are reused across components:
Drawer drawer = drawer().id("drw")
.onToggle((e, c, expanded) -> console.log("Drawer expanded: " + expanded));
ARIA Methods
Set ARIA attributes usingaria<Attribute>() methods for accessibility:
Navigation navigation = navigation(flat)
.ariaScrollBackLabel("← back")
.ariaScrollForwardLabel("→ forward");
Component Hierarchy
All components extend from either:BaseComponent- Base class for HTML element-based componentsBaseComponentSVG- Base class for SVG element-based components
Common Interfaces
Components implement common interfaces to provide consistent behavior:Modifiers.*- Toggle component flags (e.g.,plain(),inline())Closeable- For components with closeable popupsComponentContext,HasIdentifier,HasItems- For parent-child component relationshipsComponentIcon,ComponentIconAndText- For components with icons and textComponentProgress- For components showing progressExpandable- For components with expandable contentHasValue,HasObservableValue- For components with valuesValidatable,ValidationStatus- For components with validation
Available Components
This package provides a comprehensive set of PatternFly components including:
Actions & Controls: Button, Switch, Slider, Number input
Navigation: Navigation, Breadcrumb, Tabs, Jump links, Wizard
Data Display: Table, Data list, Card, Label, Badge, Timestamp
Feedback: Alert, Modal, Notification, Progress, Spinner, Skeleton
Forms: Form, Input group, Text input group
Menus: Dropdown, Menu, Toolbar, Toggle group
Containers: Accordion, Drawer, Panel, Popover, Tooltip, Empty state
Page Layout: Page, Sidebar, Masthead, Skip to content, Back to top
Content: Content, Title, Divider, Icon, Brand, Avatar
Advanced: Code block, Tree view, Expandable section, Hint, Help
Example: Building a Page
Here's a complete example showing how components work together:body().add(page()
.addSkipToContent(skipToContent("main-id"))
.addMasthead(masthead()
.addMain(mastheadMain()
.addToggle(mastheadToggle())
.addBrand(mastheadBrand()
.addLogo(mastheadLogo("/"))))
.addContent(mastheadContent()
.addToolbar(toolbar())))
.addSidebar(pageSidebar()
.addBody(pageSidebarBody()
.addNavigation(navigation(flat)
.addItem(navigationItem("get-started", "Get started", "/get-started"))
.addItem(navigationItem("get-involved", "Get involved", "/get-involved")))))
.addMain(pageMain("main-id")
.addSection(pageSection()
.add(content()
.add(title(1, "PatternFly - Java"))
.add(p()
.add("PatternFly Java is a 100% Java implementation of PatternFly."))))));
- See Also:
-
ClassDescriptionAsyncItems<T,
R> Interface to be implemented by (sub)components that have an icon.Interface to be implemented by (sub)components that have an icon and a text and where the order is important.Interface to be implemented by (sub)components that support some kind of visual progress.The component registry is a singleton that manages the registration and lookup of PatternFly (sub)components perComponentTypeand name.Contains methods and default implementations for components that are expandable.This interface represents a (sub)component that has an identifier.The HasItems interface represents a component that can contain a collection of items.HasValue<T>Internal class used by components likeNavigationorTabthat provide buttons to scroll their items horizontally.The template component is a template for creating new components.