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: