title: JPanel won't show up in JFrame(main class) - Beginner Java
body: <p>I'm  just starting out swing in Java... I have this problem about creating a separate JPanel class to be put in the main class (the one with JFrame), that the JPanel won't show up in the main class. The program can run but only the frame would show up. I was hoping that I would see the panel with the 'hallo' label but no.</p>
  
  <p>I know I've been looking for the other solutions in this site, but I didn't really get some of it. </p>
  
  <p>This is my JPanel class:</p>
  
  <pre><code>import javax.swing.*;
  
  public class CreatePanel extends JPanel
  {
      private JPanel panel = new JPanel();
      private JLabel narrate;
  
      public void setNarrate(String label)
      {
          narrate = new JLabel(label);
          panel.add(narrate);
          panel.setVisible(true);
      }
  
      public JPanel getPanel()
      {
          return panel;
      }
  }
  </code></pre>
  
  <p>This is the main class with the JFrame:</p>
  
  <pre><code>import javax.swing.*;
  
  public class Maine extends JFrame
  {
      private static JFrame frame = new JFrame();
  
      public static void main(String[] args)
      {
          new Maine();
  
          CreatePanel panel1 = new CreatePanel();
  
          panel1.setNarrate("Hallo");
          panel1.getPanel();
          frame.add(panel1);
      }
  
      public Maine()
      {
          frame.setTitle("Detective Game");
          frame.setSize(500,500);
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          frame.setVisible(true);
          frame.setLocationRelativeTo(null);
          frame.setIconImage(new ImageIcon("agent.png").getImage());
      }
  }
  </code></pre>