title: Nothing drawn when drawing in a JPanel
body: <p>I'm trying to draw a rectangle in the JPanel however it wont show up, It works in the frame however.</p>
  
  <p>if you uncomment //frame.getContentPane().add(rect); //Will draw if its in the frame
      and comment     frame.getContentPane().add(panel); // but not in the panel
        the rectangle will draw.</p>
  
  <p>Thanks for the help.</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.Graphics2D;
  
  import javax.swing.JComponent;
  import javax.swing.JFrame;
  import javax.swing.JPanel;
  
  public class DrawingRect{
  
      public static void main(String[] args) {
          DrawingRect d = new DrawingRect();
      }
  
    public DrawingRect(){
  
       JFrame frame = new JFrame("Drawing a rect");
       frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       frame.setPreferredSize(new Dimension (500,500));
  
       Rect rect = new Rect();
  
       JPanel panel = new JPanel();
       panel.setPreferredSize(new Dimension (500,500));
       panel.setVisible(true);
  
       panel.add(rect);
  
      //frame.getContentPane().add(rect); //Will draw if its in the frame
      frame.getContentPane().add(panel); // but not in the panel
  
  
       frame.pack();
       frame.setVisible(true);  
  
  
  
       panel.repaint();
       frame.repaint();
  
  
  
    }
  
    public class Rect extends JComponent{
  
      private static final long serialVersionUID = 1L;
  
          public void paint(Graphics g)
          {
              g.setColor(Color.black);
              g.drawRoundRect(10, 10, 100, 100, 20, 20);  
          }
      }
  
  }
  </code></pre>