< prev index next >

modules/javafx.controls/src/main/java/javafx/scene/control/ColorPicker.java

Print this page




  57  * colorPicker.setOnAction(new EventHandler() {
  58  *     public void handle(Event t) {
  59  *         Color c = colorPicker.getValue();
  60  *         System.out.println("New Color's RGB = "+c.getRed()+" "+c.getGreen()+" "+c.getBlue());
  61  *     }
  62  * });
  63  * </code></pre>
  64  *
  65  * <p>The ColorPicker control's appearance can be styled in three ways: a simple Button mode,
  66  * MenuButton mode or SplitMenuButton mode. The default is MenuButton mode.
  67  * For a Button like appearance the style class to use is {@link #STYLE_CLASS_BUTTON STYLE_CLASS_BUTTON}
  68  * and for SplitMenuButton appearance and behavior, the style class to use is
  69  * {@link #STYLE_CLASS_SPLIT_BUTTON STYLE_CLASS_SPLIT_BUTTON}.
  70  *
  71  * <pre><code>
  72  * colorPicker.getStyleClass().add("button");
  73  * </code></pre>
  74  * or
  75  * <pre><code>
  76  * colorPicker.getStyleClass().add("split-button");
  77  * </pre><code>
  78  * @since JavaFX 2.2
  79  */
  80 public class ColorPicker extends ComboBoxBase<Color> {
  81 
  82     /**
  83      * The style class to specify a Button like appearance of ColorPicker control.
  84      */
  85     public static final String STYLE_CLASS_BUTTON = "button";
  86 
  87     /**
  88      * The style class to specify a SplitMenuButton like appearance of ColorPicker control.
  89      */
  90     public static final String STYLE_CLASS_SPLIT_BUTTON = "split-button";
  91 
  92     /**
  93      * The custom colors added to the Color Palette by the user.
  94      */
  95     private ObservableList<Color> customColors = FXCollections.<Color>observableArrayList();
  96     /**
  97      * Gets the list of custom colors added to the Color Palette by the user.

  98      */
  99     public final ObservableList<Color>  getCustomColors() {
 100         return customColors;
 101     }
 102 
 103     /**
 104      * Creates a default ColorPicker instance with a selected color set to white.
 105      */
 106     public ColorPicker() {
 107         this(Color.WHITE);
 108     }
 109 
 110     /**
 111      * Creates a ColorPicker instance and sets the selected color to the given color.
 112      * @param color to be set as the currently selected color of the ColorPicker.
 113      */
 114     public ColorPicker(Color color) {
 115         setValue(color);
 116         getStyleClass().add(DEFAULT_STYLE_CLASS);
 117     }


  57  * colorPicker.setOnAction(new EventHandler() {
  58  *     public void handle(Event t) {
  59  *         Color c = colorPicker.getValue();
  60  *         System.out.println("New Color's RGB = "+c.getRed()+" "+c.getGreen()+" "+c.getBlue());
  61  *     }
  62  * });
  63  * </code></pre>
  64  *
  65  * <p>The ColorPicker control's appearance can be styled in three ways: a simple Button mode,
  66  * MenuButton mode or SplitMenuButton mode. The default is MenuButton mode.
  67  * For a Button like appearance the style class to use is {@link #STYLE_CLASS_BUTTON STYLE_CLASS_BUTTON}
  68  * and for SplitMenuButton appearance and behavior, the style class to use is
  69  * {@link #STYLE_CLASS_SPLIT_BUTTON STYLE_CLASS_SPLIT_BUTTON}.
  70  *
  71  * <pre><code>
  72  * colorPicker.getStyleClass().add("button");
  73  * </code></pre>
  74  * or
  75  * <pre><code>
  76  * colorPicker.getStyleClass().add("split-button");
  77  * </code></pre>
  78  * @since JavaFX 2.2
  79  */
  80 public class ColorPicker extends ComboBoxBase<Color> {
  81 
  82     /**
  83      * The style class to specify a Button like appearance of ColorPicker control.
  84      */
  85     public static final String STYLE_CLASS_BUTTON = "button";
  86 
  87     /**
  88      * The style class to specify a SplitMenuButton like appearance of ColorPicker control.
  89      */
  90     public static final String STYLE_CLASS_SPLIT_BUTTON = "split-button";
  91 
  92     /**
  93      * The custom colors added to the Color Palette by the user.
  94      */
  95     private ObservableList<Color> customColors = FXCollections.<Color>observableArrayList();
  96     /**
  97      * Gets the list of custom colors added to the Color Palette by the user.
  98      * @return the list of custom colors
  99      */
 100     public final ObservableList<Color>  getCustomColors() {
 101         return customColors;
 102     }
 103 
 104     /**
 105      * Creates a default ColorPicker instance with a selected color set to white.
 106      */
 107     public ColorPicker() {
 108         this(Color.WHITE);
 109     }
 110 
 111     /**
 112      * Creates a ColorPicker instance and sets the selected color to the given color.
 113      * @param color to be set as the currently selected color of the ColorPicker.
 114      */
 115     public ColorPicker(Color color) {
 116         setValue(color);
 117         getStyleClass().add(DEFAULT_STYLE_CLASS);
 118     }
< prev index next >