Adding a border to each element in a JList

Change the default cell renderer as in following example:

import javax.swing.border.*;
import javax.swing.*;
import java.util.*;
import java.awt.*;
public class Main {
   public static void main(String args[]) {
      JFrame frame = new JFrame("JList Background Demonstration");
      final ImageIcon imageIcon = new ImageIcon("bg1.jpg");
      Vector v = new Vector();
      for (int i=0; i<10; i++) {
         v.addElement("Item #" + i);
      JList list = new JList(v);
      list.setCellRenderer(new BorderCellRenderer(new BevelBorder(BevelBorder.LOWERED)));
//      list.setCellRenderer(new BorderCellRenderer(new BevelBorder(BevelBorder.RAISED)));
//      list.setCellRenderer(new BorderCellRenderer(new EtchedBorder(EtchedBorder.LOWERED)));
//      list.setCellRenderer(new BorderCellRenderer(new EtchedBorder(EtchedBorder.RAISED)));
      frame.getContentPane().add(BorderLayout.CENTER, list); //new JScrollPane(list));
class BorderCellRenderer extends DefaultListCellRenderer implements ListCellRenderer {
   AbstractBorder border;
   public BorderCellRenderer(AbstractBorder border) {
      this.border = border;
   public Component getListCellRendererComponent(
      JList list,
      Object value,            // value to display
      int index,               // cell index
      boolean isSelected,      // is the cell selected
      boolean cellHasFocus)    // the list and the cell have the focus
      Component c = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
      ((JComponent) c).setBorder(border);
      return c;