Top Description Fields Constructors Methods
javafx.scene.control

public Class ColorPicker

extends ComboBoxBase<Color>
Class Inheritance
Imports
javafx.collections.FXCollections, .ObservableList, javafx.scene.paint.Color, javafx.scene.control.skin.ColorPickerSkin

ColorPicker control allows the user to select a color from either a standard palette of colors with a simple one click selection OR define their own custom color.

The value is the currently selected javafx.scene.paint.Color. An initial color can be set by calling setColor or via the constructor. If nothing is specified, a default initial color is used.

The ColorPicker control provides a color palette with a predefined set of colors. If the user does not want to choose from the predefined set, they can create a custom color by interacting with a custom color dialog. This dialog provides RGB, HSB and Web modes of interaction, to create new colors. It also lets the opacity of the color to be modified.

Once a new color is defined, users can choose whether they want to save it or just use it. If the new color is saved, this color will then appear in the custom colors area on the color palette. Also getCustomColors returns the list of saved custom colors.

The promptText is not supported and hence is a no-op. But it may be supported in the future.

 ColorPicker colorPicker = new ColorPicker();
colorPicker.setOnAction(e -> {
    Color c = colorPicker.getValue();
    System.out.println("New Color's RGB = "+c.getRed()+" "+c.getGreen()+" "+c.getBlue());
});
Image of the ColorPicker control

The ColorPicker control's appearance can be styled in three ways: a simple Button mode, MenuButton mode or SplitMenuButton mode. The default is MenuButton mode. For a Button like appearance the style class to use is STYLE_CLASS_BUTTON and for SplitMenuButton appearance and behavior, the style class to use is STYLE_CLASS_SPLIT_BUTTON.

colorPicker.getStyleClass().add("button");

or

colorPicker.getStyleClass().add("split-button");
Since
JavaFX 2.2

Field Summary

Modifier and TypeField and Description
private ObservableList<Color>
customColors

The custom colors added to the Color Palette by the user.

private static final String
public static final String
STYLE_CLASS_BUTTON

The style class to specify a Button like appearance of ColorPicker control.

public static final String
STYLE_CLASS_SPLIT_BUTTON

The style class to specify a SplitMenuButton like appearance of ColorPicker control.

Inherited from javafx.scene.control.ComboBoxBase:
ON_HIDDENON_HIDINGON_SHOWINGON_SHOWN

Constructor Summary

AccessConstructor and Description
public
ColorPicker()

Creates a default ColorPicker instance with a selected color set to white.

public
ColorPicker(Color
to be set as the currently selected color of the ColorPicker.
color
)

Creates a ColorPicker instance and sets the selected color to the given color.

Method Summary

Modifier and TypeMethod and Description
protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control.

public final ObservableList<Color>

Returns:

the list of custom colors
getCustomColors
()

Gets the list of custom colors added to the Color Palette by the user.

Inherited from javafx.scene.control.ComboBoxBase:
armarmedPropertydisarmeditablePropertyexecuteAccessibleActiongetOnActiongetOnHiddengetOnHidinggetOnShowinggetOnShowngetPromptTextgetValuehideisArmedisEditableisShowingonActionPropertyonHiddenPropertyonHidingPropertyonShowingPropertyonShownPropertypromptTextPropertyqueryAccessibleAttributesetEditablesetOnActionsetOnHiddensetOnHidingsetOnShowingsetOnShownsetPromptTextsetValueshowshowingPropertyvalueProperty

Field Detail

customColorsback to summary
private ObservableList<Color> customColors

The custom colors added to the Color Palette by the user.

DEFAULT_STYLE_CLASSback to summary
private static final String DEFAULT_STYLE_CLASS

Hides javafx.scene.control.ComboBoxBase.DEFAULT_STYLE_CLASS.

STYLE_CLASS_BUTTONback to summary
public static final String STYLE_CLASS_BUTTON

The style class to specify a Button like appearance of ColorPicker control.

STYLE_CLASS_SPLIT_BUTTONback to summary
public static final String STYLE_CLASS_SPLIT_BUTTON

The style class to specify a SplitMenuButton like appearance of ColorPicker control.

Constructor Detail

ColorPickerback to summary
public ColorPicker()

Creates a default ColorPicker instance with a selected color set to white.

ColorPickerback to summary
public ColorPicker(Color color)

Creates a ColorPicker instance and sets the selected color to the given color.

Parameters
color:Color

to be set as the currently selected color of the ColorPicker.

Method Detail

createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Doc from javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).

Annotations
@Override
getCustomColorsback to summary
public final ObservableList<Color> getCustomColors()

Gets the list of custom colors added to the Color Palette by the user.

Returns:ObservableList<Color>

the list of custom colors