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
invalid reference
org.patternfly.handler
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:
-
ClassDescriptionA functional interface that defines a handler for adding items to components.AsyncItems<T,
R> A functional interface that represents an asynchronous computation yielding an iterable result.A utility class for managing add, update, and remove event handlers for a component.Base class for PatternFly components backed by anHTMLElement.Base class for PatternFly components backed by anSVGElement.Interface for components that can be closed, such as alerts, modals, and popovers.Marker interface for all PatternFly components, providing access to theComponentType.Base class for components that delegate to a lazily assigned root element.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.Public, type-keyed singleton registry for PatternFly components that exist at most once per page.Enumerates all PatternFly component types with their short ID and OUIA component name.Contains methods and default implementations for components that are expandable.HasAsyncItems<E extends Element, C extends HasItems<E,C, S>, S extends HasIdentifier<? extends HTMLElement, ?>> Represents a component or entity that can asynchronously manage items and their associated operations.This interface represents a (sub)component that has an identifier.HasItems<E extends Element, C extends HasItems<E,C, S>, S extends HasIdentifier<? extends HTMLElement, ?>> The HasItems interface represents a component that can contain a collection of items.Interface for components that can bind to anObservableValueand react to value changes.HasValue<T>Interface for components that expose a typed value, such as form controls and inputs.Defines the position of an icon relative to the text in aComponentIconAndTextcomponent.A utility class for handlingEventType.keydown,EventType.keyup,EventType.input, andEventType.changeevents in components with an HTML input element.Ordered<E extends Element, C extends HasItems<E,C, S>, S extends HasIdentifier<? extends HTMLElement, ?>> The Ordered interface maintains its elements in a specific order.Functional interface for handling the removal of items from a component that contains a collection of items.Internal class used by components likeNavigationorTabthat provide buttons to scroll their items horizontally.Defines how items can be selected in components that support selection, such as menus and navigation.Defines the severity levels used by alerts, notifications, and other status-aware components.Base class for sub-components that are part of a larger PatternFly component, such as card headers or modal bodies.A functional interface that defines a handler invoked when an item is updated in a component implementingHasItems.Interface for form components that support validation status display, such as text inputs and form selects.Defines the validation states available forValidatableform components.