Skip to main content

Overview

JCard is a flexible container component that extends JavaFX’s VBox. It provides a structured layout with optional header (title, subtitle, toolbar), body content, footer, and built-in support for scrolling and collapse functionality.

Constructor

JCard()
constructor
Creates an empty card.
JCard(String titleText, Node content)
constructor
Convenience constructor with title and content.
JCard(String titleText, String subtitleText)
constructor
Convenience constructor with title and subtitle.

Methods

Header Configuration

setTitle(String titleText)
JCard
Sets the card title. Creates the header section if it doesn’t exist.
setSubtitle(String subtitleText)
JCard
Sets the card subtitle. Appears below the title in the header.
addToolbarItem(Node node)
JCard
Adds a node to the header toolbar (positioned on the right side).
setLine(boolean show)
void
Adds or removes a border line below the header.

Content Configuration

setBody(Node content)
JCard
Sets the main content of the card body.
Sets the footer content at the bottom of the card.
makeScrollable()
JCard
Makes the card body scrollable by wrapping it in a ScrollPane.

Collapse Functionality

setCollapsible(boolean collapsible)
JCard
Enables or disables the collapsible functionality. Adds a chevron icon to the header toolbar.
setExpanded(boolean expanded)
JCard
Sets the expanded/collapsed state of the card.

Styling

addClass(String... styleClasses)
JCard
Adds custom CSS style classes to the card.

Style Classes

card
String
Base style class applied to the card container
card-header
String
Applied to the header container
card-header-line
String
Applied to the header when setLine(true) is called
card-title-box
String
Applied to the container holding title and subtitle
card-title
String
Applied to the title label
card-subtitle
String
Applied to the subtitle label
card-toolbar
String
Applied to the toolbar container in the header
card-body
String
Applied to the body container
Applied to the footer container
card-scroll
String
Applied to the scroll pane when makeScrollable() is called
card-chevron
String
Applied to the collapse/expand chevron icon

Example Usage

// Basic card with title and content
JCard card = new JCard("Card Title", new Label("Card content"));

// Card with title, subtitle, and toolbar
JCard card = new JCard()
    .setTitle("User Profile")
    .setSubtitle("Manage your account settings")
    .addToolbarItem(new JButton("Edit"))
    .setLine(true)
    .setBody(new Label("Profile content here"))
    .setFooter(new HBox(new JButton("Save"), new JButton("Cancel")));

// Scrollable collapsible card
JCard card = new JCard()
    .setTitle("Details")
    .setBody(new VBox(/* long content */))
    .makeScrollable()
    .setCollapsible(true)
    .setExpanded(false);

Source

com.jjarroyo.components.JCard in JCard.java:6

Build docs developers (and LLMs) love