Skip to content

ColorSelector

Since 2.2.1

ColorSelector is a full-featured HSB (Hue–Saturation–Brightness) color picker. It extends BindableUIElement<Integer> and its value is the selected color as a packed ARGB integer. It includes:

  • An HSB gradient picking surface that can switch between hue, saturation, and brightness axes.
  • A hue/alpha slider.
  • RGB and hex text fields for direct input.
  • A color preview swatch.
  • Clipboard copy support.

INFO

Everything documented on UIElement (layout, styles, events, data bindings, etc.) applies here too.


Usage

java
var picker = new ColorSelector();
picker.setValue(0xFF4080FF, false); // initial ARGB color
picker.registerValueListener(color -> System.out.printf("Color: #%08X%n", color));
parent.addChild(picker);

Internal Structure

FieldDescription
pickerContainerContainer holding the main HSB gradient surface.
colorPreviewSwatch showing the currently selected color.
colorSliderSlider for the primary HSB axis (hue, saturation, or brightness).
alphaSliderSlider for the alpha (transparency) channel.
hsbButtonButton that cycles between H, S, and B pick modes.
textContainerContainer for the RGB and hex text field inputs.
hexConfiguratorText input for entering hex color codes.

Value Binding

ColorSelector extends BindableUIElement<Integer>:

java
picker.bind(DataBindingBuilder.intVal(
    () -> config.getColor(),
    color -> config.setColor(color)
).build());

See Data Bindings for full details.


Fields

NameTypeAccessDescription
pickerContainerUIElementpublic finalHSB gradient canvas.
colorPreviewUIElementpublic finalColor preview swatch.
colorSliderUIElementpublic finalPrimary HSB axis slider.
alphaSliderUIElementpublic finalAlpha channel slider.
hsbButtonButtonpublic finalCycles the active HSB pick mode (H → S → B → H).
textContainerUIElementpublic finalContainer for text inputs.
hexConfiguratorStringConfiguratorpublic finalHex color input field.

Methods

MethodReturnsDescription
setValue(Integer, boolean)ColorSelectorSets the ARGB color value; second param controls notification.
getValue()IntegerReturns the current ARGB color.
registerValueListener(Consumer<Integer>)voidRegisters a listener called whenever the color changes.

Released under the MIT License.