title: JPanel not showing when added to another JPanel
body: <p>I'm trying to create a game in Java - the game is going to be a 2-D scrolling game. I have a class called CornPanel which extends <code>JPanel</code> and shows a corn plant - the <code>CornPanel</code>'s are what will be moved across the screen. I know the <code>CornPanel</code> class is working because it shows up when I add it directly to a <code>JFrame</code>. However, when I try to add a <code>CornPanel</code> to another <code>JPanel</code> and then add that <code>JPanel</code> to the JFrame, the <code>CornPanel</code> doesn't show up. </p>
  
  <p>Here's my <code>CornPanel</code> class (abbreviated - I took out the stuff I'm pretty sure isn't causing the problem):</p>
  
  <pre><code>package game;
  
  import java.awt.Graphics;
  import java.io.File;
  import java.io.IOException;
  import javax.imageio.ImageIO;
  import javax.swing.JPanel;
  
  public class CornPanel extends JPanel{
  
      BufferedImage cornImage;
  
      public CornPanel(){
          loadImages();
      }
  
      public void loadImages(){
          try{
              cornImage = ImageIO.read(new File("src\\cornBasic.png"));
          } catch(IOException e){
              e.printStackTrace();
          }
      }
  
      protected void paintComponent(Graphics g){
          g.drawImage(cornImage, 0, 0, cornImage.getWidth(), cornImage.getHeight(), this);
      }
  }
  </code></pre>
  
  <p>My Game class:</p>
  
  <pre><code>package game;
  
  import java.awt.Color;
  import java.awt.Graphics;
  import java.util.ArrayList;
  import java.util.Random;
  
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  
  public class Game extends JFrame{
  
      ArrayList&lt;CornPanel&gt; cornPanels;
      JPanel gameContainer;
  
      public Game(){
          cornPanels = new ArrayList&lt;CornPanel&gt;();
          gameContainer = new JPanel();
          setSize(1000, 1000);
          setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setBackground(new Color(98, 249, 255));
          setExtendedState(JFrame.MAXIMIZED_BOTH);
          getContentPane().add(gameContainer);
  
          addCornPanel();
          setVisible(true);
      }
  
      public void addCornPanel(){
  
          CornPanel cornPanel = new CornPanel();
          cornPanels.add(cornPanel);
          gameContainer.add(cornPanel);
          cornPanel.setVisible(true); 
          getContentPane().repaint();
          repaint();
      }
  
  
      public static void main(String[] args) {
          Game game = new Game();
      }
  }
  </code></pre>
  
  <p>Note: I got it to work by setting the LayoutManager for both the <code>JFrame</code> and <code>gameContainer</code> to <code>new GridLayout(1,1)</code>, but the problem is that then I can't use <code>setLocation()</code> on the CornPanel in order to make it animate. If there's a way to do it without <code>setLocation()</code> let me know. Also, I took out a lot of code I don't think is necessary for diagnosing the problem - hopefully I didn't take out too much.</p>