Creating a background for a JList

Here’s an example:

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) {
         Image image = imageIcon.getImage();
         { 
            setOpaque(false);
         }
         public void paintComponent(Graphics g) {
            g.drawImage(image, 0, 0, this);
            super.paintComponent(g);
         }
      };
      list.setCellRenderer(new OpaqueCellRenderer());
      
      frame.getContentPane().add(BorderLayout.CENTER, list); //new JScrollPane(list));
      frame.setDefaultCloseOperation(3);
      frame.pack();
      frame.setVisible(true);
   }
}
 
class OpaqueCellRenderer extends DefaultListCellRenderer implements ListCellRenderer {
   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);
 
      if (isSelected) {
         ((JComponent) c).setOpaque(true);
         c.setBackground(list.getSelectionBackground());
         c.setForeground(list.getSelectionForeground());
      }
      else {
         ((JComponent) c).setOpaque(false);
         c.setBackground(list.getBackground());
         c.setForeground(list.getForeground());
      }
 
      return c;
   }
}

bg1.jpg: