title: Jlist Custom Renderer
body: <p>I'm trying to add a i guess you would call it a sub list to each item on a list. I've built a custom renderer that gives the below output. As you can see something isn't right here an i've had no luck tracking down an answer to my problem. I'm guessing i need to change something in the layout of the panel to get the correct result but no idea what. </p>
  
  <p><a href="http://i.stack.imgur.com/jCKjJ.jpg" rel="nofollow">http://i.stack.imgur.com/jCKjJ.jpg</a></p>
  
  <pre><code>import java.awt.BorderLayout;
  import java.awt.Component;
  import java.awt.Container;
  import java.awt.GridLayout;
  import java.util.Random;
  import javax.swing.JCheckBox;
  import javax.swing.JLabel;
  import javax.swing.JList;
  import javax.swing.JPanel;
  import javax.swing.JSeparator;
  import javax.swing.ListCellRenderer;
  import javax.swing.border.EmptyBorder;
  
  public class GAListRendererAdv extends Container implements ListCellRenderer {
  private static final long serialVersionUID = 1L;
  private JPanel pnl = new JPanel();
  private Random rnd = new Random();
  
  public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
          boolean cellHasFocus) {
  
      pnl.setLayout(new BorderLayout(0, 0));
  
      JCheckBox chckbxSomething = new JCheckBox("something");
      pnl.add(chckbxSomething, BorderLayout.NORTH);
  
      JSeparator separator = new JSeparator();
      pnl.add(separator, BorderLayout.CENTER);
  
      JPanel panel_1 = new JPanel();
      panel_1.setBorder(new EmptyBorder(0, 35, 0, 0));
      pnl.add(panel_1, BorderLayout.SOUTH);
      panel_1.setLayout(new GridLayout(0, 1, 0, 0));
  
      int rndNum = rnd.nextInt(5) + 1;
  
      for (int i = 0; i &lt; rndNum; i ++) {
      JLabel lblNewLabel2 = new JLabel("New label");
      panel_1.add(lblNewLabel2);
      }
  
      return pnl;
  }
  }
  </code></pre>