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..
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());
});
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");
| Modifier and Type | Field and Description |
|---|---|
| private ObservableList | 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. |
| Access | Constructor and Description |
|---|---|
| public | |
| 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. |
| Modifier and Type | Method and Description |
|---|---|
| protected Skin | createDefaultSkin()
Overrides javafx. Create a new instance of the default skin for this control. |
| public final ObservableList | Returns: the list of custom colorsGets the list of custom colors added to the Color Palette by the user. |
| customColors | back to summary |
|---|---|
| private ObservableList<Color> customColors The custom colors added to the Color Palette by the user. | |
| DEFAULT_STYLE_CLASS | back to summary |
|---|---|
| private static final String DEFAULT_STYLE_CLASS Hides javafx. | |
| STYLE_CLASS_BUTTON | back to summary |
|---|---|
| public static final String STYLE_CLASS_BUTTON The style class to specify a Button like appearance of ColorPicker control. | |
| STYLE_CLASS_SPLIT_BUTTON | back to summary |
|---|---|
| public static final String STYLE_CLASS_SPLIT_BUTTON The style class to specify a SplitMenuButton like appearance of ColorPicker control. | |
| ColorPicker | back to summary |
|---|---|
| public ColorPicker() Creates a default ColorPicker instance with a selected color set to white. | |
| ColorPicker | back to summary |
|---|---|
| public ColorPicker(Color color) Creates a ColorPicker instance and sets the selected color to the given color.
| |
| createDefaultSkin | back to summary |
|---|---|
| protected Skin Overrides javafx. Doc from javafx. 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 | |
| getCustomColors | back to summary |
|---|---|
| public final ObservableList Gets the list of custom colors added to the Color Palette by the user.
| |