title: unable to add a paintComponent panel to a frame
body: <p>I'm having problems adding a JPanel, which has a paintComponent in it, to a JFrame.<br>
  If this is the only thing I add to the frame, it works.  But as soon as I add a layout manager and add other components to the JFrame, it no longer shows the panel with the painting!</p>
  
  <p>To make this clearer ...</p>
  
  <p>This is the code that works and the JPanel is successfully shown:</p>
  
  <p>The panel that draws the sign (in reality i am not trying to paint hello, this is to simply the code here)</p>
  
  <pre><code>public class SignPanel2 extends JPanel {
  public int hello;
  
  public void paintComponent(Graphics comp) {
      Graphics g = (Graphics) comp;
      g.setColor(Color.LIGHT_GRAY);
      g.fillRect(70, 250, 150, 150);
  
      g.setColor(Color.BLACK); 
  
      if (hello &gt; 0) 
          g.drawString("h",135, 270);
  
      if (hello &gt; 1 ) 
          g.drawString("h e",135, 270);
  
      if (hello &gt; 2) 
          g.drawString("h e l",135, 270);
  
      if (hello &gt; 3) 
          g.drawString("h e l l",135, 270);
  
      if (hello &gt; 4) 
          g.drawString("h e l l o",135, 270);
  }
  
  }
  </code></pre>
  
  <p>The frame i put the panel on:</p>
  
  <pre><code>public class SignFrame extends JFrame {
  
  // the constructor method
  public SignFrame () {
  
      super("This is the title of the Sign Frame");
      setSize(300,500);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      // make a container for the frame
      Container content = getContentPane();
  
      // call from the drawing panel
      SignPanel2 signpanel = new SignPanel2();
      // change class variable of SignPanel
      signpanel.hello = 5;
      signpanel.repaint();
  
  
      // add signpanel to container
      content.add(signpanel);
  
      setContentPane(content);
  
      setVisible(true);
  
  }
  
  }
  </code></pre>
  
  <p>The main class</p>
  
  <pre><code>public class TheSignMain {
  
  public static void main (String[] args) {
  
      SignFrame signframe = new SignFrame();
  
  }
  
  }
  </code></pre>
  
  <p>The above works perfectly fine and gives me a frame with the desired drawing in it.  </p>
  
  <p>But if I add other components to the frame and add a layout manager, it no longer shows me the painting.  even if I use repaint().<br>
  I have to include a layout manager, otherwise it adds the panel with the painting, but not the other components.
  This is how my frame class looks now, and this is where i'm having problems.</p>
  
  <p>public class SignFrame extends JFrame {</p>
  
  <pre><code>// the constructor method
  public SignFrame () {
  
      super("This is the title of the Sign Frame");
      setSize(300,500);
      setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
      // make a container for the frame
      Container content = getContentPane();
  
  
      // need a layout manager to decide the arrangement of the components on the container
      FlowLayout flo = new FlowLayout();
      // designate the layout manager to the container
      content.setLayout(flo);
  
  
      // make components
      JPanel buttons = new JPanel();
      JButton play = new JButton("Play");
      JButton pause = new JButton("Pause");
      JButton stop = new JButton("Stop");
      // add components to a panel
      buttons.add(play);
      buttons.add(pause);
      buttons.add(stop);
      // add panel to frame container
      content.add(buttons);
  
  
      // call from the drawing panel
      SignPanel2 signpanel = new SignPanel2();
      // change class variable of SignPanel
      signpanel.hello = 5;
      signpanel.repaint();
  
  
      // add signpanel to container
      content.add(signpanel);
  
      setContentPane(content);
  
      setVisible(true);
  
  }
  
  }
  </code></pre>
  
  <p>I am totally new to Java, so any help will be much appreciated.
  Sorry for all that code and thanks for your help!!</p>