class JColorButton extends JButton {

    private final static int ICON_WIDTH = 16;
    private final static int ICON_HEIGHT = 16;
    private final static Color DISABLED_BORDER = new Color(200, 200, 200);
    private final static Color DISABLED_FILL = new Color(220, 220, 220);
    public static String EVENT_COLOR = "color";
    private Color color;
    private boolean includeOpacity;

    public JColorButton(Color originalColor) {
        this(originalColor, false, false);
    }

    public JColorButton(Color originalColor, boolean rightClick, boolean includeOpacity) {
        this.includeOpacity = includeOpacity;
        this.color = originalColor;
        setIcon(new Icon() {

            @Override
            public int getIconWidth() {
                return ICON_WIDTH;
            }

            @Override
            public int getIconHeight() {
                return ICON_HEIGHT;
            }

            @Override
            public void paintIcon(Component c, Graphics g, int x, int y) {<FILL_FUNCTION_BODY>}
        });
        if (rightClick) {
            addMouseListener(new MouseAdapter() {

                @Override
                public void mouseClicked(MouseEvent e) {

                    if (SwingUtilities.isRightMouseButton(e)) {
                        Color newColor = ColorPicker.showDialog(WindowManager.getDefault().getMainWindow(), color,
                            JColorButton.this.includeOpacity);
                        if (newColor != null) {
                            setColor(newColor);
                        }
                    }
                }
            });
        } else {
            addActionListener(new ActionListener() {

                @Override
                public void actionPerformed(ActionEvent e) {
                    Color newColor = ColorPicker.showDialog(WindowManager.getDefault().getMainWindow(), color,
                        JColorButton.this.includeOpacity);
                    if (newColor != null) {
                        setColor(newColor);
                    }
                }
            });
        }
    }

    public Color getColor() {
        return color;
    }

    public void setColor(Color color) {
        if (color != this.color || (color != null && !color.equals(this.color))) {
            Color oldColor = this.color;
            this.color = color;
            firePropertyChange(EVENT_COLOR, oldColor, color);
            repaint();
        }
    }

    public float[] getColorArray() {
        return new float[] {color.getRed() / 255f, color.getGreen() / 255f, color.getBlue() / 255f,
            color.getAlpha() / 255f};
    }

    public void setIncludeOpacity(boolean includeOpacity) {
        this.includeOpacity = includeOpacity;
    }
}

                if (c.isEnabled()) {
                    g.setColor(Color.BLACK);
                    g.drawRect(x + 2, y + 2, ICON_WIDTH - 5, ICON_HEIGHT - 5);
                    if (color != null) {
                        g.setColor(color);
                        g.fillRect(x + 3, y + 3, ICON_WIDTH - 6, ICON_HEIGHT - 6);
                    }
                } else {
                    g.setColor(DISABLED_BORDER);
                    g.drawRect(x + 2, y + 2, ICON_WIDTH - 5, ICON_HEIGHT - 5);
                    g.setColor(DISABLED_FILL);
                    g.fillRect(x + 3, y + 3, ICON_WIDTH - 6, ICON_HEIGHT - 6);
                }

            
<methods>public void <init>() ,public void <init>(javax.swing.Icon) ,public void <init>(java.lang.String) ,public void <init>(javax.swing.Action) ,public void <init>(java.lang.String, javax.swing.Icon) ,public javax.accessibility.AccessibleContext getAccessibleContext() ,public java.lang.String getUIClassID() ,public boolean isDefaultButton() ,public boolean isDefaultCapable() ,public void removeNotify() ,public void setDefaultCapable(boolean) ,public void updateUI() <variables>private static final java.lang.String uiClassID