title: GridBagLayout - How can I make this cell fill the space below it?
body: <p>I'm creating a JFrame with 4 JPanels.  Using GridBagLayout, I create three rows and two columns, two panels per column.  By changing the blue panel's cellheight from 1 to 2 I can make it cover the cell below it.  I'd like to do the same for the green panel, to fill the space below it.  Here's what my code currently produces:</p>
  
  <p><a href="https://i.stack.imgur.com/GWaBa.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GWaBa.png" alt="enter image description here"></a></p>
  
  <p>I tried changing the green panel's gridheight to 2 but I end up with this:</p>
  
  <p><a href="https://i.stack.imgur.com/2MUEb.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2MUEb.png" alt="enter image description here"></a></p>
  
  <p>Am I using GridBagLayout incorrectly?  What is the appropriate way of doing this? </p>
  
  <p>Here's my code:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Container;
  import java.awt.GridBagConstraints;
  import java.awt.GridBagLayout;
  import java.awt.Insets;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  public class Main {
  
      public static void main(String[] args) {
          JFrame frame = new JFrame();
          addComponents(frame.getContentPane());
          frame.setSize(800, 600);
          frame.setVisible(true);
      }
  
      public static void addComponents(Container contentPane) {
          contentPane.setLayout(new GridBagLayout());
          GridBagConstraints c = new GridBagConstraints();
          c.insets = new Insets(3,3,3,3);
          c.fill = GridBagConstraints.BOTH;
  
          c.gridx = 0;
          c.gridy = 0;
          c.gridwidth = 1;
          c.gridheight = 2;
          c.weightx = 1;
          c.weighty = 0.85;
          JPanel panel1 = new JPanel();
          panel1.setBackground(Color.BLUE);
          contentPane.add(panel1, c);
  
          c.gridx = 0;
          c.gridy = 2;
          c.gridwidth = 1;
          c.gridheight = 1;
          c.weightx = 1.1;
          c.weighty = 0.35;
          JPanel panel2 = new JPanel();
          panel2.setBackground(Color.YELLOW);
          contentPane.add(panel2, c);
  
          c.gridx = 1;
          c.gridy = 0;
          c.gridwidth = 1;
          c.gridheight = 1;
          c.weightx = 0.15;
          c.weighty = 0.5;
          JPanel panel3 = new JPanel();
          panel3.setBackground(Color.RED);
          contentPane.add(panel3, c);
  
          c.gridx = 1;
          c.gridy = 1;
          c.gridwidth = 1;
          c.gridheight = 1;
          c.weightx = 0.38;
          c.weighty = 0.5;
          JPanel panel4 = new JPanel();
          panel4.setBackground(Color.GREEN);
          contentPane.add(panel4, c);
      }
  }
  </code></pre>