title: Who is calling the paintComponent() method in my class?
body: <p>I have a simple class that paints a graphic in a JPanel. This is my class:</p>
  
  <pre><code>import java.awt.Color;
  import java.awt.Dimension;
  import java.awt.Graphics;
  import javax.swing.JPanel;
  
  class Drawing_panel extends JPanel {
      public void paintComponent(Graphics g) {
      super.paintComponent(g);       
      this.setBackground(Color.white);
      g.setColor(Color.red);
      g.fillRect(150, 80, 20, 20);
  }  
  
  public Dimension getPreferredSize(){
      return new Dimension(500,500);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>I have another class that instantiates this one:</p>
  
  <pre><code>Drawing_panel dp = new Drawing_panel();
  </code></pre>
  
  <p>There is no constructor in the <code>Drawing_panel</code> class and/or no explicit call to either the <code>paintComponent()</code> or <code>getPreferredSize()</code> methods. I assume the method is being called in the parent <code>JPanel</code> constructor, but I did not see the calls there either.</p>