title: Multiple JPanel not being printed in front of background
body: <p>I wanted to create a Calendar that creates itself dinamically depending on the month it is based of. At first, I created a background that will be used on any months, and its dimensions are 700x500 (700/7 for each day and 500/5 since every month but 28-days-February-starting-in-Monday has 5 rows of weeks). I did this with this sentences:</p>
  
  <pre><code>public class Graph {
  
      private final int sizeX = 700;
      private final int sizeY = 500;
      private Calendar calendar;
  
  
      public Graph(Calendar calendar) {
          this.calendar = calendar;
          JFrame frame = new JFrame();
          graph(frame);
      }
  
      public void graph(JFrame frame) {
          buildBackground(frame);
      }
  
      private void buildBackground(JFrame frame) {
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
          frame.setSize(sizeX, sizeY);
          JPanel panel = new Background(sizeX, sizeY);
          frame.add(panel);
          frame.validate();
          frame.repaint();
      }
  }
  
  public class Background extends JPanel {
  
      private int sizeX;
      private int sizeY;
  
      public Background(int sizeX, int sizeY) {
          this.sizeX = sizeX;
          this.sizeY = sizeY;
      }
  
      @Override
      public void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.setColor(Color.DARK_GRAY);
          g.fillRect(0, 0, sizeX, sizeY);
      }
  }
  </code></pre>
  
  <p>And that works correctly, a dark gray background is created correctly. The problem appears when I try to create small rectangles that represents the days; I designed a class which I want to represent those rectangles on a certain coordinates:</p>
  
  <pre><code>public class DayRectangle extends JPanel {
  
      private int posX;
      private int posY;
      private int day;
  
      public DayRectangle(int posX, int posY, int day) {
          this.posX = posX;
          this.posY = posY;
          this.day = day;
      }
  
      @Override
      public void paintComponent(Graphics g) {
          super.paintComponent(g);
          g.fillRect(posX, posY, 60, 60);
      }
  
      public Dimension getPreferredSize() {
          return new Dimension (60, 60);
      }
  
      @Override
      public String toString() {
          return String.format("(%d,%d):%d", posX, posY, day);
      }
  }
  </code></pre>
  
  <p>Rectangles' coordinates are created correctly, since this are the content of the <code>ArrayList</code> of <code>DayRectangle</code>:</p>
  
  <pre><code>[(20,20):1, (120,20):2, (220,20):3, (320,20):4, (420,20):5, (520,20):6, (620,20):7, (20,120):8, (120,120):9, (220,120):10, (320,120):11, (420,120):12, (520,120):13, (620,120):14, (20,220):15, (120,220):16, (220,220):17, (320,220):18, (420,220):19, (520,220):20, (620,220):21, (20,320):22, (120,320):23, (220,320):24, (320,320):25, (420,320):26, (520,320):27, (620,320):28, (20,420):29, (120,420):30, (220,420):31]
  </code></pre>
  
  <p>They start on <code>(20, 20)</code> because I wanted to let some gaps between those rectangles.</p>
  
  <p>The main problem is that no rectangle is printed when I execute this code:</p>
  
  <pre><code>public void graph(JFrame frame) {
      buildBackground(frame);
      frame.getGraphics().setColor(Color.WHITE);
      JPanel panel;
      for (DayRectangle d : arraylist) {
          panel = d;
          frame.add(panel);
          frame.repaint();
      }
  }
  </code></pre>
  
  <p>What am I doing wrong? Why is nothing being printed? Thanks.</p>