Class ColorPicker

All Implemented Interfaces:
Styleable, EventTarget, Skinnable

public class ColorPicker
extends ComboBoxBase<Color>

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 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 Details

    • STYLE_CLASS_BUTTON

      public static final String STYLE_CLASS_BUTTON
      The style class to specify a Button like appearance of ColorPicker control.
      See Also:
      Constant Field Values
    • STYLE_CLASS_SPLIT_BUTTON

      public static final String STYLE_CLASS_SPLIT_BUTTON
      The style class to specify a SplitMenuButton like appearance of ColorPicker control.
      See Also:
      Constant Field Values
  • Constructor Details

    • ColorPicker

      public ColorPicker()
      Creates a default ColorPicker instance with a selected color set to white.
    • ColorPicker

      public ColorPicker​(Color color)
      Creates a ColorPicker instance and sets the selected color to the given color.
      Parameters:
      color - to be set as the currently selected color of the ColorPicker.
  • Method Details

    • getCustomColors

      public final ObservableList<Color> getCustomColors()
      Gets the list of custom colors added to the Color Palette by the user.
      Returns:
      the list of custom colors