Package org.patternfly.component


package org.patternfly.component
Provides PatternFly component implementations for building web applications in Java.

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:

These base classes implement Elemento interfaces for element manipulation.

Common Interfaces

Components implement common interfaces to provide consistent behavior:

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:
  • Class
    Description
    BaseComponent<E extends elemental2.dom.HTMLElement, B extends TypedBuilder<E,B>>
    Base class for PatternFly components backed by an HTMLElement.
    BaseComponentSVG<E extends SVGElement, B extends TypedBuilder<E,B>>
    Base class for PatternFly components backed by an SVGElement.
    Closeable<E extends elemental2.dom.Element, B extends TypedBuilder<E,B>>
    Interface for components that can be closed, such as alerts, modals, and popovers.
    Marker interface for all PatternFly components, providing access to the ComponentType.
    ComponentDelegate<E extends elemental2.dom.HTMLElement, B extends TypedBuilder<E,B>>
    Base class for components that delegate to a lazily assigned root element.
    ComponentIcon<E extends elemental2.dom.Element, B extends TypedBuilder<E,B>>
    Interface to be implemented by (sub)components that have an icon.
    ComponentIconAndText<E extends elemental2.dom.Element, B extends TypedBuilder<E,B>>
    Interface to be implemented by (sub)components that have an icon and a text and where the order is important.
    ComponentProgress<E extends elemental2.dom.Element, B extends TypedBuilder<E,B>>
    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.
    Expandable<E extends elemental2.dom.Element, B extends TypedBuilder<E,B>>
    Contains methods and default implementations for components that are expandable.
    Defines the position of an icon relative to the text in a ComponentIconAndText component.
    KicHandler<C extends BaseComponent<elemental2.dom.HTMLElement, C>>
    A utility class for handling EventType.keydown, EventType.keyup, EventType.input, and EventType.change events in components with an HTML input element.
    Internal class used by components like Navigation or Tab that 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.
    SubComponent<E extends elemental2.dom.HTMLElement, B extends TypedBuilder<E,B>>
    Base class for sub-components that are part of a larger PatternFly component, such as card headers or modal bodies.
    Validatable<E extends elemental2.dom.HTMLElement, B extends TypedBuilder<E,B>>
    Interface for form components that support validation status display, such as text inputs and form selects.
    Defines the validation states available for Validatable form components.