    01: import java.awt.*;
    02: import java.beans.*;
    03: import javax.swing.*;
    04: import javax.swing.event.*;
    05:
    06: /**
    07:    A property editor for the Color type that uses a JColorChooser.
    08: */
    09: public class CustomColorEditor extends PropertyEditorSupport
    10: {
    11:    public String getAsText()
    12:    {
    13:       return null;
    14:    }
    15:
    16:    public boolean supportsCustomEditor()
    17:    {
    18:       return true;
    19:    }
    20:
    21:    public Component getCustomEditor()
    22:    {
    23:       final JColorChooser chooser = new JColorChooser();
    24:       chooser.getSelectionModel().addChangeListener(
    25:          new ChangeListener()
    26:          {
    27:             public void stateChanged(ChangeEvent event)
    28:             {
    29:                setValue(chooser.getColor());
    30:             }
    31:          });
    32:       return chooser;
    33:    }
    34:
    35:    public boolean isPaintable()
    36:    {
    37:       return true;
    38:    }
    39:
    40:    public void paintValue(Graphics g, Rectangle boundingBox)
    41:    {
    42:       Graphics2D g2 = (Graphics2D) g;
    43:       Color color = (Color) getValue();
    44:       g2.setColor(color);
    45:       g2.fill(boundingBox);
    46:       g2.setColor(Color.BLACK);
    47:       g2.draw(boundingBox);
    48:    }
    49: }