Skip to main content

Overview

JCheckBox is a customizable checkbox component that extends JavaFX’s CheckBox with theme-aware styling options.

Constructors

JCheckBox()

Creates a checkbox with no text label.
JCheckBox checkbox = new JCheckBox();

JCheckBox(String text)

Creates a checkbox with the specified text label.
text
String
The text label to display next to the checkbox
JCheckBox checkbox = new JCheckBox("Accept terms");

Properties

colorStyle

colorStyle
CheckBoxStyle
default:"PRIMARY"
The color style of the checkbox
Available Values:
  • PRIMARY - Primary theme color
  • SUCCESS - Success/green color
  • DANGER - Danger/red color
  • WARNING - Warning/yellow color
  • INFO - Info/blue color
  • DARK - Dark color
  • SECONDARY - Secondary theme color

size

size
CheckBoxSize
default:"DEFAULT"
The size of the checkbox
Available Values:
  • SMALL - Small checkbox
  • DEFAULT - Default/medium checkbox
  • LARGE - Large checkbox

Methods

setColorStyle(CheckBoxStyle style)

Sets the color style of the checkbox.
style
CheckBoxStyle
required
The color style to apply
checkbox.setColorStyle(JCheckBox.CheckBoxStyle.SUCCESS);

getColorStyle()

Returns the current color style.
colorStyle
CheckBoxStyle
The current color style of the checkbox
CheckBoxStyle style = checkbox.getColorStyle();

colorStyleProperty()

Returns the color style property for binding.
colorStyleProperty
ObjectProperty<CheckBoxStyle>
The observable property for color style
checkbox.colorStyleProperty().addListener((obs, old, newVal) -> {
    System.out.println("Style changed to: " + newVal);
});

setSize(CheckBoxSize size)

Sets the size of the checkbox.
size
CheckBoxSize
required
The size to apply
checkbox.setSize(JCheckBox.CheckBoxSize.LARGE);

getSize()

Returns the current size.
size
CheckBoxSize
The current size of the checkbox
CheckBoxSize size = checkbox.getSize();

sizeProperty()

Returns the size property for binding.
sizeProperty
ObjectProperty<CheckBoxSize>
The observable property for size
checkbox.sizeProperty().addListener((obs, old, newVal) -> {
    System.out.println("Size changed to: " + newVal);
});

Example Usage

import com.jjarroyo.components.JCheckBox;

// Create a checkbox with custom style and size
JCheckBox checkbox = new JCheckBox("Enable notifications");
checkbox.setColorStyle(JCheckBox.CheckBoxStyle.PRIMARY);
checkbox.setSize(JCheckBox.CheckBoxSize.DEFAULT);

// Listen to selection changes
checkbox.selectedProperty().addListener((obs, wasSelected, isSelected) -> {
    if (isSelected) {
        System.out.println("Checkbox selected");
    }
});

// Set initial state
checkbox.setSelected(true);

CSS Style Classes

The component applies the following style classes:
  • j-checkbox - Base style class
  • checkbox-primary, checkbox-success, etc. - Color style classes
  • checkbox-sm, checkbox-md, checkbox-lg - Size style classes

Build docs developers (and LLMs) love