Skip to main content

JButton

A styled button component that extends JavaFX’s Button class with automatic theme support and icon integration.

Basic Usage

import com.jjarroyo.components.JButton;
import com.jjarroyo.components.JIcon;

// Simple button
JButton button = new JButton("Click Me");

// Button with text
JButton textButton = new JButton("Submit");

// Button with icon
JButton iconButton = new JButton("Save", JIcon.SAVE);

Variants

// Primary button (default)
JButton primary = new JButton("Primary");

// Success variant
JButton success = new JButton("Success")
    .addClass("btn-success");

// Danger variant
JButton danger = new JButton("Delete")
    .addClass("btn-danger");

// Warning variant
JButton warning = new JButton("Warning")
    .addClass("btn-warning");

// Secondary variant
JButton secondary = new JButton("Secondary")
    .addClass("btn-secondary");

Sizes

// Small button
JButton small = new JButton("Small")
    .addClass("btn-sm");

// Default size
JButton normal = new JButton("Normal");

// Large button
JButton large = new JButton("Large")
    .addClass("btn-lg");

With Icons

// Icon with text
JButton saveBtn = new JButton("Save", JIcon.SAVE);

// Programmatically set icon
JButton btn = new JButton("Delete");
btn.setIcon(JIcon.DELETE);

// Remove icon
btn.setIcon(null);

API Reference

Constructors

JButton()
constructor
Creates an empty button
JButton(String text)
constructor
Creates a button with the specified text
JButton(String text, JIcon icon)
constructor
Creates a button with text and an icon

Methods

addClass(String... styleClasses)
JButton
Adds one or more CSS style classes to the button. Automatically removes default btn-primary when a new variant is added.
button.addClass("btn-success", "btn-lg");
setIcon(JIcon icon)
void
Sets or removes the button icon. Pass null to remove the icon.
button.setIcon(JIcon.CHECK);

JBadge

A label component designed for displaying tags, counts, or status indicators.

Basic Usage

import com.jjarroyo.components.JBadge;

// Simple badge
JBadge badge = new JBadge("New");

// Badge with variant
JBadge successBadge = new JBadge("Active", "badge-success");

// Badge with icon
JBadge iconBadge = new JBadge("5", JIcon.NOTIFICATIONS);

Variants

JBadge primary = new JBadge("Primary");
JBadge success = new JBadge("Success").addClass("badge-success");
JBadge danger = new JBadge("Error").addClass("badge-danger");
JBadge warning = new JBadge("Warning").addClass("badge-warning");
JBadge info = new JBadge("Info").addClass("badge-info");

Sizes & Shapes

// Small badge
JBadge small = new JBadge("3").addClass("badge-sm");

// Large badge
JBadge large = new JBadge("99+").addClass("badge-lg");

// Circular badge (for counts)
JBadge circle = new JBadge("5").addClass("badge-circle");

API Reference

Constructors

JBadge()
constructor
Creates an empty badge
JBadge(String text)
constructor
Creates a badge with text
JBadge(String text, JIcon icon)
constructor
Creates a badge with text and icon
JBadge(String text, String... styleClasses)
constructor
Creates a badge with text and custom style classes

Methods

addClass(String... styleClasses)
JBadge
Adds CSS style classes, automatically managing variant replacements
setIcon(JIcon icon)
void
Sets or removes the badge icon

JChip

An interactive tag/chip component inspired by Material Design, perfect for filters, tags, and categories.

Basic Usage

import com.jjarroyo.components.JChip;
import com.jjarroyo.components.JChip.Variant;
import com.jjarroyo.components.JChip.Size;

// Simple chip
JChip chip = new JChip("JavaFX");

// Chip with icon
JChip iconChip = new JChip("Technology", JIcon.CODE.view());

Variants

// Filled variant (default)
JChip filled = new JChip("Filled")
    .setVariant(Variant.FILLED)
    .setColor("primary");

// Outlined variant
JChip outlined = new JChip("Outlined")
    .setVariant(Variant.OUTLINED)
    .setColor("success");

// Soft variant
JChip soft = new JChip("Soft")
    .setVariant(Variant.SOFT)
    .setColor("info");

Colors

chip.setColor("primary");   // Blue
chip.setColor("success");   // Green
chip.setColor("danger");    // Red
chip.setColor("warning");   // Yellow
chip.setColor("info");      // Cyan
chip.setColor("slate");     // Gray

Sizes

JChip small = new JChip("Small").setChipSize(Size.SM);
JChip medium = new JChip("Medium").setChipSize(Size.MD);
JChip large = new JChip("Large").setChipSize(Size.LG);

Dismissible Chips

HBox container = new HBox();
JChip dismissible = new JChip("Remove Me")
    .setDismissible(true)
    .setOnDismiss(() -> {
        container.getChildren().remove(dismissible);
        System.out.println("Chip removed!");
    });

container.getChildren().add(dismissible);

Complete Example

HBox tagContainer = new HBox(8);

String[] tags = {"Java", "JavaFX", "UI", "Design"};
for (String tag : tags) {
    JChip chip = new JChip(tag)
        .setColor("primary")
        .setVariant(Variant.SOFT)
        .setDismissible(true)
        .setOnDismiss(() -> tagContainer.getChildren().remove(chip));
    
    tagContainer.getChildren().add(chip);
}

API Reference

Constructors

JChip(String text)
constructor
Creates a chip with the specified text
JChip(String text, Node icon)
constructor
Creates a chip with text and an icon node

Methods

setColor(String color)
JChip
Sets the color variant: primary, success, danger, warning, info, slate
setVariant(Variant variant)
JChip
Sets the visual variant: FILLED, OUTLINED, SOFT
setChipSize(Size size)
JChip
Sets the size: SM, MD, LG
setText(String text)
JChip
Updates the chip text
getText()
String
Returns the current text
setIcon(Node icon)
JChip
Sets or updates the icon
setDismissible(boolean dismissible)
JChip
Enables or disables the close button
setOnDismiss(Runnable onDismiss)
JChip
Sets the callback to execute when the chip is dismissed

Available Icons

All components support the JIcon enum with 150+ icons. Common examples:
  • Navigation: ARROW_BACK, ARROW_FORWARD, HOME, MENU, CLOSE
  • Actions: ADD, DELETE, EDIT, SEARCH, SETTINGS, SAVE
  • Status: CHECK, ERROR, WARNING, INFO
  • Social: PERSON, GROUP, SHARE, FAVORITE
  • File: FILE, FOLDER, UPLOAD, DOWNLOAD
See JIcon.java for the complete list.

Build docs developers (and LLMs) love