title: Dynamic generation of buttons in Java
body: <p>I am trying to dynamically generate a form.  Basically, I want to load a list of items for purchase, and generate a button for each.  I can confirm that the buttons are being generated with the debugger, but they aren't being displayed.  This is inside a subclass of <code>JPanel</code>:</p>
  
  <pre><code>private void generate() {
      JButton b = new JButton("height test");
      int btnHeight = b.getPreferredSize().height;
      int pnlHeight = this.getPreferredSize().height;
      int numButtons = pnlHeight / btnHeight;
  
      setLayout(new GridLayout(numButtons, 1));
  
      Iterator&lt;Drink&gt; it = DrinkMenu.iterator();
  
      for (int i = 0; i &lt;= numButtons; ++i) {
          if (!it.hasNext()) {
              break;
          }
          final Drink dr = it.next();
          b = new DrinkButton(dr);
          b.addActionListener(new ActionListener() {
              public void actionPerformed(ActionEvent e) {
                  order.addDrink(dr);
          }});
          add(b);
      }
      revalidate();
  }
  </code></pre>
  
  <p><code>DrinkButton</code> is a subclass of <code>JButton</code>.  Any ideas?</p>