# JColorWell, JPalette Demo

## What Is It

This demos two components that help users select colors: a `com.pump.swing.JPalette` and a `com.pump.swing.JColorWell`.

## How To Use It

The simplest usage resembles:

    JColorWell colorWell = new JColorWell();

The `JColorWell` will present a `JPalette` in a floating popup window when it is clicked.

If you want to use a `JPalette` by itself (with no color well), it's similarly easy to instantiate:

    JPalette palette = new JPalette();

## How It Works

Both internally keep track of their currently selected `Color` using a `javax.swing.colorchooser.ColorSelectionModel`. They can also share the same `ColorSelectionModel` if you want two components to stay in sync.

### JPalette

The `JPalette` is a grid of color swatches. Each cell is a separate `JToggleButton`, so the palette should be fully accessible/navigable.

The demo offers a slider to control the swatch cell size. As a rule of thumb: I'd recommend not using a cell size below 40-50 pixels. From an accessibility standpoint: some users may have difficulty targeting an area smaller than 40x40. (To my knowledge this isn't a codified standard, though.)

The default color palette is currently the Flat UI Palette v1, but I tossed in the Fluent and Metro sets as well. Additionally there are two custom palettes we used (simply named "small" and "large") that offer basic primary colors, grayscales and flesh tones.

### JColorWell

The `JColorWell` is a single color swatch. This compactness makes it great for inspectors that need to list several consecutive controls.

You can define two different behaviors: one for a single click (or down arrow key), and another for a double-click (or enter key). The default single-click behavior is to show a `JPalette` in a popup. The default double-click behavior is to show a `JColorPicker`.

## Discussion

Well over a decade ago our original implementation of a color palette didn't feature cells. Every pixel was a unique color, so it was a spectrum with thousands of choices. We figured more is better, right? But that's a common rookie mistake. As The Power of Persuasion points out:

> The greater the number of choices, the happier the consumer - so it's assumed.

> In a recent series of experiments ... a group of Columbia University chocolate lovers were given a choice between six different flavors of Godiva chocolates. A second group was asked to select between thirty different flavors. Subjects given the extensive flavor choices rated their selection as less tasty, less satisfying and less enjoyable than did the limited-choice group. The thirty-flavor subjects expressed more regrets about their selection and were less likely to choose chocolate as payment for participating in the experiment.

Sure enough: it didn't take long for our users to specifically request a grid-like model. In hindsight providing a fixed set of options offers two advantages:

- Users aren't overwhelmed with choices.
- Users can easily re-select the same set of colors.