class PaletteIcon implements Icon {

    private static final int COLOR_WIDTH = 13;
    private static final int COLOR_HEIGHT = 13;
    private static final Color BORDER_COLOR = new Color(0x444444);
    private final Color[] colors;
    private final int maxColors;

    public PaletteIcon(Color[] colors) {
        this(colors, colors.length);
    }

    public PaletteIcon(Color[] colors, int maxColors) {
        this.colors = colors;
        this.maxColors = Math.min(maxColors, colors.length);
    }

    @Override
    public int getIconWidth() {
        return COLOR_WIDTH * maxColors;
    }

    @Override
    public int getIconHeight() {
        return COLOR_HEIGHT + 2;
    }

    @Override
    public void paintIcon(Component c, Graphics g, int x, int y) {<FILL_FUNCTION_BODY>}
}

        Graphics2D g2 = (Graphics2D) g;
        g2.setStroke(new BasicStroke(1));

        for (int i = 0; i < maxColors; i++) {
            g2.setColor(colors[i]);
            g2.fillRect(x + 2 + i * COLOR_WIDTH, y, COLOR_WIDTH, COLOR_HEIGHT);
            g2.setColor(BORDER_COLOR);
            g2.drawRect(x + 2 + i * COLOR_WIDTH, y, COLOR_WIDTH, COLOR_HEIGHT);
        }
    
<no_super_class>