JColorPicker Demo

What Is It

The com.pump.swing.JColorPicker is an alternative to Swing's default javax.swing.JColorChooser that presents a color wheel and other Photoshop-inspired UI controls.

How To Use It

You can create a JColorPicker that can be inserted anywhere in your UI by calling:

JColorPicker picker = new JColorPicker(true, false);
picker.addPropertyChangeListener(JColorPicker.SELECTED_COLOR_PROPERTY, pcl);

Or you can invoke a modal dialog by calling:

boolean includeOpacity = true;
Color c = JColorPicker.showDialog(window, initialColor, includeOpacity);
`

How It Works

The JColorPicker mostly manages the data model and a series of UI controls that can be toggled on/off as needed. Since a color is generally represented by 3 numbers and our UI can only present 2D data (either as a rectangle or a circle): we end up holding one number constant. The default constant is "Brightness", but the JColorPicker (and this demo) lets you choose any of the 6 values: red, green, blue, hue, saturation, brightness.

The JColorPickerPanel is the JComponent that actually renders the large gradient wheel/rectangle. The JColorPicker, by contrast, is the container that embeds the JColorPickerPanel and dozens of other UI controls.

Discussion

The original motivation for this class was simple: I didn't like how the JColorChooser looks:

screenshots of the JColorChooser

Personally I think palettes are the best way to choose a color (so the JColorChooser is off to a good start), but specifically my main critiques include:

The JColorPicker is loosely modeled after options I observed in Photoshop. (But as a disclaimer: I wrote it over a decade ago, and I haven't opened Photoshop lately.) My ideal usage is to pick just one view (usually a brightness-based wheel) and not let the user further configure it.

The JColorWell is a separate component that offers both a palette and a dialog. The JColorPicker is what I consider the "most advanced" option. I want to use it when the user has signaled that they want really granular control over their color choice.