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 using add<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 using on<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 using aria<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
These base classes implement Elemento interfaces for element manipulation.
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:
-
ClassDescriptionBase class for PatternFly components backed by an
HTMLElement.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.Defines the position of an icon relative to the text in aComponentIconAndTextcomponent.KicHandler<C extends BaseComponent<elemental2.dom.HTMLElement, C>>A utility class for handlingEventType.keydown,EventType.keyup,EventType.input, andEventType.changeevents in components with an HTML input element.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.Predicate that determines whether a menu should stay open after an interaction.Base class for sub-components that are part of a larger PatternFly component, such as card headers or modal bodies.Interface for form components that support validation status display, such as text inputs and form selects.Defines the validation states available forValidatableform components.