title: Adding a JPanel to a JLayeredPane causes paints and resizes to have no effect
body: <p>I am trying to add a JPanel (well, several) to a JLayeredPane. However, when I do so, the paint component method of the JPanel seems to have no effect. An example is included below:</p>
  
  <pre><code>import javax.swing.*;
  import java.awt.*;
  
  public class Example {
  
      public static void main(String[] args) {
  
          // This Works as expected
          JFrame usingPanel = new JFrame();
          JPanel p = new JPanel();
          p.add(new BluePanel());
          usingPanel.setContentPane(p);
          usingPanel.pack();
          usingPanel.setVisible(true);
  
          // This makes the frame but does not paint the BluePanel
          JFrame usingLayer = new JFrame();
          JLayeredPane l = new JLayeredPane();
          l.setPreferredSize(new Dimension(200,200));
          l.add(new BluePanel(), JLayeredPane.DEFAULT_LAYER);
          JPanel p2 = new JPanel();
          p2.add(l);
          usingLayer.setContentPane(p2);
          usingLayer.pack();
          usingLayer.setVisible(true);
      }
  
  
     static class BluePanel extends JPanel{
  
          public BluePanel(){
              setPreferredSize(new Dimension(200,200));
          }
  
          @Override
          public void paintComponent(Graphics g){
              super.paintComponent(g);
              g.setColor(Color.BLUE);
              g.fillRect(0, 0, 200, 200);
          }
  
  
      }
  
  
  }
  </code></pre>
  
  <p>Why is this? and what are the possible solutions?</p>