public class ColorPicker
  Comment     Returned-by     Constructor-argument     Method-argument     Field-type     Type-bound     Links  

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.


 final ColorPicker colorPicker = new ColorPicker();
 colorPicker.setOnAction(new EventHandler() {
     public void handle(Event t) {
         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");
 

extends ComboBoxBase<Color>

Since:  JavaFX 2.2