title: Swing layout with miglayout and nested panels
body: <p>I have a Swing program using SwingLayout. The structure of the Swing components looks like this.</p>
  
  <pre><code>JFrame
      JPanel (Cardlayout)
          JPanel (Miglayout) - Main panel
              Jpanel (Flowlayout) - Checkbox Panel
              JPanel (Flowlayout) - Option Panel
  </code></pre>
  
  <p>My problem right now is that I'm not sure how to prevent the checkbox panel from growing. I don't want it to "push" out the column that it's in to the right. I want Wraplayout (which works fine on the option panel) to wrap the content of the checkbox panel when it grows too big.</p>
  
  <p>This is the view of it from the Windowsbuilder GUI inside of Eclipse. The panel with the label "sites" in it is the Checkbox Panel. Directly to the right of the Checkbox panel is the Option panel. The big panel containing both of them is the main panel.
  <a href="http://i.imgur.com/S7Njo.png" rel="nofollow">http://i.imgur.com/S7Njo.png</a></p>
  
  <p>This is what happens when I add too many checkboxes
  <a href="http://i.imgur.com/f2SZz.png" rel="nofollow">http://i.imgur.com/f2SZz.png</a></p>
  
  <p>My main problem is that I don't understand why setting "grow 0" on the column constraint for the first column in mainpanel doesn't prevent it from growing when the component inside gets too big as I add new checkboxes to the site panel (the site panel can have an arbitrary number of checkboxes).</p>
  
  <p>This is my miglayout for the main panel.</p>
  
  <pre><code>mainPanel.setLayout(new MigLayout("", "[][grow]", "[][][][][][][][grow]"));
  </code></pre>
  
  <p>Here are my component constraints for when I add the checkbox panel</p>
  
  <pre><code>siteCheckBoxPanel = new JPanel();
  mainPanel.add(siteCheckBoxPanel, "cell 0 0,alignx left,gapx 0px,aligny center");
  siteCheckBoxPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
  </code></pre>
  
  <p>I've also tried it without flow layout, and that doesn't fix anything. Any insight you could provide would be great! I'm also happy to provide more information if people have questions. FYI I've also tried "grow 0" on both the column and row constraint for the cell that the Checkbox Panel is inside.</p>
  
  <p>Here's an SSCCE. You can grab the source below. The only dependency you need is miglayout. You can click on the button to add checkboxes.</p>
  
  <p><a href="https://dl.dropbox.com/u/20614368/Test.java" rel="nofollow">https://dl.dropbox.com/u/20614368/Test.java</a></p>
  
  <pre><code>import java.awt.CardLayout;
  import java.awt.Color;
  import java.awt.EventQueue;
  import java.awt.event.ActionEvent;
  
  import javax.swing.AbstractAction;
  import javax.swing.Action;
  import javax.swing.JButton;
  import javax.swing.JCheckBox;
  import javax.swing.JFrame;
  import javax.swing.JLabel;
  import javax.swing.JPanel;
  import javax.swing.JTextArea;
  import javax.swing.border.EmptyBorder;
  
  import net.miginfocom.swing.MigLayout;
  
  
  public class Test extends JFrame {
  
  
      public static void main(String[] args) {
          EventQueue.invokeLater(new Runnable() {
              private Test frame;
  
              public void run() {
                  try {
                      frame = new Test();
                      frame.setVisible(true);
                  } catch (Exception e) {
                      e.printStackTrace();
                  }
              }
          });
      }
  
      private JPanel contentPane;
      private JPanel mainPanel;
      private JPanel optionPanel;
      private JButton btnUploadImages;
      private JLabel thumbnailLabel;
      private JTextArea textArea;
      private JPanel checkboxPanel;
      private final Action action = new SwingAction();
  
      /**
       * Create the frame.
       */
      public Test() {
          setVisible(true);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setBounds(100, 100, 1098, 846);
          contentPane = new JPanel();
          contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
          setContentPane(contentPane);
          contentPane.setLayout(new CardLayout(0, 0));
  
          mainPanel = new JPanel();
          mainPanel.setName("");
          contentPane.add(mainPanel, "name_329556913535654");
          mainPanel.setLayout(new MigLayout("", "[][grow]", "[][][][][][][][grow]"));
  
  
          JLabel lblPicture = new JLabel("Picture");
          mainPanel.add(lblPicture, "cell 0 1");
  
          optionPanel = new JPanel();
          optionPanel.setBackground(Color.red);
          mainPanel.add(optionPanel, "cell 1 0 1 5,grow");
  
          btnUploadImages = new JButton("Upload Images");
          btnUploadImages.setAction(action);
  
          thumbnailLabel = new JLabel("");
          mainPanel.add(thumbnailLabel, "cell 0 4");
  
          textArea = new JTextArea();
          mainPanel.add(btnUploadImages, "cell 0 6");
  
          checkboxPanel = new JPanel();
          checkboxPanel.setBackground(Color.green);
          mainPanel.add(checkboxPanel, "flowx,cell 0 0");
  
          JLabel lblSites = new JLabel("Sites");
          checkboxPanel.add(lblSites);
  
  
      }
      private class SwingAction extends AbstractAction {
          public SwingAction() {
              putValue(NAME, "Add checkbox");
              putValue(SHORT_DESCRIPTION, "Some short description");
          }
          public void actionPerformed(ActionEvent e) {
              JCheckBox box = new JCheckBox();
              box.setName("Foobar!");
              checkboxPanel.add(box);
              contentPane.validate();
              contentPane.repaint();
          }
      }
  }
  </code></pre>