title: JComponents getting smaller in GridLayout
body: <p>I'm trying to create a Game of Life type of application, and I have some problems with drawing the cells. I have one large <code>JPanel</code> (<code>RectGridPanel</code>) acting as the ground for the simulation, and on that panel I draw out a grid by adding smaller panels (<code>GridElement</code>) in a <code>GridLayout</code>. Then I try to add my cells to these smaller panels.</p>
  <pre><code>import java.awt.Dimension;
  import java.awt.Color;
  import java.awt.event.*;
  import java.awt.GridLayout;
  import java.awt.BorderLayout;
  import javax.swing.BorderFactory;
  import javax.swing.JPanel;
  
  public class GridElement extends JPanel
  {
      
      public GridElement()
      {
          this.setLayout(new BorderLayout());
          
          this.setMinimumSize(new Dimension(40, 40));
          
          this.setBorder(BorderFactory.createLineBorder(Color.BLACK));
      }
      
      public void createCell()
      {
          Cell newCell = new RectCell();
          this.add(newCell, BorderLayout.CENTER);
      }
  }
  </code></pre>
  <pre><code>import java.awt.*;
  
  public class RectCell extends JPanel
  {
      
      public RectCell()
      {
          
          this.setPreferredSize(new Dimension(40, 40));
          
          this.setBackground(Color.BLUE);
      }
  }
  </code></pre>
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics2D;
  import java.awt.GridLayout;
  import java.awt.Rectangle;
  import java.awt.event.MouseEvent;
  import java.util.ArrayList;
  import java.util.List;
  import java.awt.Graphics;
  
  public class RectGridPanel extends JPanel
  {   
      public RectGridPanel()
      {
          this.setPreferredSize(new Dimension(840, 800));
          
          this.setLayout(new GridLayout(20,21));
          
          for(int x = 0; x &lt; 21; x++)
          {
              for(int y = 0; y &lt; 20; y++)
              {
                  GridElement element = new GridElement();
                  element.createCell();
                  this.add(element);
              }
          }
      }   
  }
  
  </code></pre>
  <p>What I want to achieve is that my cells (colored blue) fill out all those <code>GridElement</code> components I created, but in reality the coloring of the cells gets smaller in size the further they are from the top left corner:</p>
  <p><a href="https://i.stack.imgur.com/cA8tn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cA8tn.png" alt="enter image description here" /></a></p>