JComboBox custom ListCellRenderer
<p>I've a problem with JComboBox custom ListCellRenderer. I want to create a combobox that let choose between 4 colors. I want the combobox shows the color by a "list" of JPanel with desired color a background. I manage to obtain quite what I want, the only problem is that when I click on item, this change color to grey not displaying anymore the original color.
Here the code:</p>

<pre><code>package custom_renderer_combobox;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.ListCellRenderer;
import javax.swing.JComboBox;

public class gui extends JFrame{

    /**
     * 
     */
    private static final long serialVersionUID = 1L;

    private Color[] colors={Color.BLACK,Color.blue,Color.cyan,Color.GRAY,Color.green,Color.MAGENTA,Color.ORANGE,Color.RED};
    gui(){
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setVisible(true);
        setSize(new Dimension(400,400));
        getContentPane().setLayout(null);

        JComboBox&lt;JPanel&gt; comboBox = new JComboBox&lt;JPanel&gt;();
        comboBox.setRenderer(new myRenderer());
        comboBox.setBounds(36, 59, 211, 20);
        getContentPane().add(comboBox);
        for(int i=0;i&lt;colors.length;i++){
            JPanel temp=new JPanel();
            temp.setOpaque(true);
            temp.setBackground(colors[i]);
            comboBox.addItem(temp);
        }
        comboBox.repaint();
    }

    class myRenderer implements ListCellRenderer{


        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            return ((JPanel) value);
        }

    }
}
</code></pre>

<p>Here some pic:</p>

<p><a href="http://i.stack.imgur.com/SmRdw.jpg" rel="nofollow">image</a></p>

<p>I think that the problem is in the custom renderer, can someone tell me what would I had to do?</p>