Skip to main content

A Single-Mouse-Gesture Color Chooser for Swing

Posted by timboudreau on June 5, 2006 at 5:56 PM PDT

Ever needed a faster, slicker way to let your users select a color in Swing? I just set up a new java.net project, which produces just such a widget. Press the mouse and a palette pops up; drag over the palette and release when the color is right; use combinations of ctrl/alt/shift to switch palettes (palettes are pluggable if you want to write your own).

The widget is the Quick Color Chooser - net.dev.java.colorchooser.ColorChooser. It's a simple Swing widget with one property of interest - color - that is incredibly easy to use.

It's actually been sitting around in contrib/ on netbeans.org for a couple of years, and the palette code dates back to 2000 - it's a port of a Delphi component I wrote in the mid nineties.
.

So the code is fairly mature and solid - I just split it out into having a separate UI delegate so it's more Swing-like and the painting behavior is overridable, but it's the same logic as before. Feedback appreciated.

If you want to try it using Matisse in NetBeans, there's a NetBeans module that installs the component in the component palette for immediate drag-and-drop use (created using BeanNetter). The module includes the javadoc.

Related Topics >>