Changing the color of every element in a JList

Customize the CellRenderer as in following example:

import javax.swing.event.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;
  
public class Main extends JFrame {
 
   public Main() {
      getContentPane().setLayout(new FlowLayout());
 
      Vector v = new Vector();
      final JList list = new JList(
         new Colorable[] { new ColoredItem("Item 1", Color.yellow),
                           new ColoredItem("Item 2"),
                           new ColoredItem("Item 3", Color.blue),
                           new ColoredItem("Item 4", Color.red),
                           new ColoredItem("Item 5", Color.green)
                         });
 
      list.setCellRenderer(new ColoredCellRenderer());
      getContentPane().add(new JScrollPane(list));    
 
      addWindowListener(new WindowAdapter() {
         public void windowClosing(WindowEvent event) {
            System.exit(0);   
         }      
      });
 
      setSize(200, 300);
   }
   
   public static void main(String[] args) {
      (new Main()).show();
   }
}
 
class ColoredCellRenderer extends DefaultListCellRenderer implements ListCellRenderer {
   public Component getListCellRendererComponent(
      JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)    
   {
      setText((value == null) ? "" : value.toString());
      Color c = ((Colorable) value).getColor();
      if (isSelected) {
         setBackground(list.getSelectionBackground());
         setForeground(c);
      }
      else {
         setBackground(list.getBackground());
         setForeground(c);
      }
 
      setEnabled(list.isEnabled());
      setFont(list.getFont());
 
      return this;
   }
}
 
class ColoredItem implements Colorable {
   Object  object;
   Color   color;
                            
   public ColoredItem(Object object, Color color) {
      this.object = object;
      this.color = color;
   }
                             
   ColoredItem(Object object) {
      this(object, Color.black);
   }
 
   public Color getColor() {
      return color;
   } 
 
   public void setColor(Color color) {
      this.color = color;
   }                           
                            
   public String toString() {
      return object.toString();
   }
}
                         
interface Colorable {
   public Color getColor();
   public void setColor(Color c);
}