Skip to main content

Overview

JHeader is a horizontal navigation header component that extends JavaFX’s HBox. It provides three main sections: left (branding), center (menu items), and right (toolbar and user profile).

Constructor

JHeader()
constructor
Creates a new header with empty sections.

Methods

Branding

setBrand(Node logo, String title)
JHeader
Sets the brand logo and title in the left section.
addMenuItem(String text, Runnable action)
JHeader
Adds a clickable menu item to the center section.
addMenuDropdown(String text, Map<String, Runnable> items)
JHeader
Adds a dropdown menu item to the center section.

Toolbar

addToolbarItem(Node node)
JHeader
Adds a custom node to the right toolbar section (appears before the user profile).

User Profile

setUserProfile(String name, String email, String initials)
JHeader
Sets the user profile information in the right section.
setUserProfile(String name, String email, String initials, Runnable onLogout)
JHeader
Sets the user profile with a logout action.

Style Classes

j-header
String
Base style class applied to the header container
j-header-brand
String
Applied to the left branding section
j-header-logo-text
String
Applied to the brand title label
j-header-menu
String
Applied to the center menu section
j-header-menu-item
String
Applied to individual menu items
j-header-toolbar
String
Applied to the right toolbar section
j-header-user-profile
String
Applied to the user profile container
j-header-user-info
String
Applied to the user info text container
j-header-user-name
String
Applied to the user name label
j-header-user-email
String
Applied to the user email label
j-header-avatar
String
Applied to the avatar container
j-header-avatar-text
String
Applied to the avatar initials text
j-popover-header
String
Applied to the popover header section (in profile dropdown)
j-popover-title
String
Applied to popover title labels
j-popover-subtitle
String
Applied to popover subtitle labels
j-popover-item
String
Applied to popover menu items

Example Usage

// Create header
JHeader header = new JHeader();

// Set branding
header.setBrand(
    new ImageView(new Image("logo.png")),
    "MyApp"
);

// Add menu items
header.addMenuItem("Home", () -> navigateHome())
      .addMenuItem("Dashboard", () -> navigateDashboard())
      .addMenuDropdown("Products", Map.of(
          "Electronics", () -> showElectronics(),
          "Clothing", () -> showClothing(),
          "Books", () -> showBooks()
      ));

// Add toolbar items
header.addToolbarItem(new JBadge("5"));
header.addToolbarItem(JIcon.BELL.view());

// Set user profile
header.setUserProfile(
    "John Doe",
    "john@example.com",
    "JD",
    () -> performLogout()
);

Behavior Notes

  • The profile dropdown displays when clicking the user avatar
  • The dropdown includes a “Cerrar Sesión” (Logout) option that triggers the onLogout action
  • Menu dropdowns use JPopover for positioning
  • Toolbar items are inserted before the user profile
  • All methods return the header instance for fluent method chaining

Dependencies

  • JPopover - Used for dropdown menus and profile menu
  • JIcon - Can be used for menu icons and toolbar items

Source

com.jjarroyo.components.JHeader in JHeader.java:12

Build docs developers (and LLMs) love