Skip to content

ColorButton

greipadmin edited this page Mar 9, 2019 · 27 revisions

Introduction

The ColorButton widget allow the user to select a color. You can use different color choosers for the color models RGB and HSB, a color wheel and a color list.

Constructor

  • ColorButton(Composite parent, int style)
    • parent the parent Composite
    • style the style of widget to construct.

Methods

  • void setRGB(RGB) set the initial color value.
  • RGB getRGB() gets the selected color or the initial color, when no color selected.
  • boolean chooseRGB() opens the color chooser and allows the user to select a color (for use inside a selection listener).
  • void setColorChooserFactory(IColorChooserFactory) sets a factory for creating the color chooser.
  • void setColorConsumer(Consumer<RGB>) sets a consumer for the selected color.
  • void setDropDownArrowVisible(boolean) switch visibility of drop down arrow.
  • boolean isDropDownArrowVisible() returns the visibility of drop down arrow.
  • You can also use all SWT Button methods.

Color choosers

  • ColorChooserHSB, selects a color by hue, brightness and saturation.
  • ColorChooserRGB, selects a color by red, green, blue.
  • ColorCircleChooser, selects a color by hue, brightness and saturation. The hue is displayed as an color circle.
  • ColorWheelChooser, selects a color from a color wheel.

A color chooser has the following features:

  • Define a color resolution (reduces the maximum number of displayed colors).
  • Show/hide RGB info.
  • Preview with old and new color.

Color picker

  • ColorPicker, selects a color from a predefined or user defined color list. When you call setRGB(RGB), the nearest color in the list is selected.

Examples

  • Sample1 demonstrates the use with a default color chooser factory and a classical selection listener.
  • Sample2 shows the use of an color consumer and the definition of a color chooser factory.
  • Sample3 shows the use of an color picker with a list of predefined colors.
  • Sample4 uses an color chooser as widget.
Clone this wiki locally