title: How do you add empty cells to GridBagLayout?
body: <p>I want to achieve this effect using GridBagLayout:</p>
  
  <pre><code>|-----------|
  |  Button1  |
  |-----------|
        |-----------|
        |  Button2  |
        |-----------|
  </code></pre>
  
  <p>I initially just placed the buttons, but GridBagLayout is ignoring the empty cells.  Now, I am trying to use Box.createHorizontalStrut(10) as spacers, but GridBagLayout is stretching the spaces to give me a 2x2 grid.  I also tried JLabels and JPanels as the spacers, but I still get a 2x2 grid. Here is my code:</p>
  
  <pre><code>import java.awt.*;
  import javax.swing.*;
  
  public class GridBagLayoutDemo extends JFrame
  {
      // class level references
      GridBagLayout layout;   
      JButton button1, button2;
  
      // constructor
      public GridBagLayoutDemo()
      {
          super("GridBagLayout Demo");
  
          layout = new GridBagLayout();
          setLayout( layout );
  
          // create components
          button1 = new JButton("Button 1");
          button2 = new JButton("Button 2");
  
          // components should be resized vertically AND horizontally (BOTH) to fill given area
          int fill = GridBagConstraints.BOTH;
  
          // if you do not fill the area, where should the component go?
          int anchor = GridBagConstraints.CENTER;
  
          // place components on the frame using a method
          placeComponent( button1, 0, 0, 2, 2, 0.5, 0.5, fill, 0, 0, 0, 0, anchor );
          placeComponent( Box.createHorizontalStrut(5), 2, 0, 1, 2, 0.5, 0.5, fill, 0, 0, 0, 0, anchor );
          placeComponent( Box.createHorizontalStrut(5), 0, 2, 1, 2, 0.5, 0.5, fill, 0, 0, 0, 0, anchor );
          placeComponent( button2, 1, 2, 2, 2, 0.5, 0.5, fill, 0, 0, 0, 0, anchor );
      }
  
      /// Place the component on the GridBag with appropriate parameters
      private void placeComponent( Component comp, int column, int row, int width, int height, double weightX, double weightY, 
              int fill, int marginTop, int marginLeft, int marginBottom, int marginRight, int anchor )
      {
          GridBagConstraints constraints = new GridBagConstraints();
          constraints.gridx = column;     // column to start
          constraints.gridy = row;        // row to start
          constraints.gridwidth = width;  // number of cells wide
          constraints.gridheight = height;  // number of cells tall
          constraints.weightx = weightX;    // when size is changed, grow in x direction
          constraints.weighty = weightY;    // when size is changed, grow in y direction
          constraints.fill = fill;        // should the component fill the given area?  GridBagConstraints.NONE, GridBagConstraints.BOTH, GridBagConstraints.CENTER, etc
          constraints.insets = new Insets( marginTop, marginLeft, marginBottom, marginRight );
          constraints.anchor = anchor;
          layout.setConstraints(comp, constraints);
          add(comp);  // place component on the frame with these parameters
      }
  
      /// launches the application
      public static void main(String[] args)
      {
          GridBagLayoutDemo app = new GridBagLayoutDemo();
          app.setSize(400, 300);
          app.setLocationRelativeTo(null);
          app.setVisible(true);
      }
  }
  </code></pre>
  
  <p>Any ideas?  Thanks!</p>