title: repaint method after add custom JPanel to JFrame
body: <p>I have this code, but <code>JPanel</code> repaint method does not work.  If I do that after add it to JFrame class  I debug it and it does not recall <code>paintComponent</code>.  </p>
  
  <p>Why is that so?</p>
  
  <pre><code>package trial;
  
  import java.awt.Color;
  import java.awt.Graphics;
  import javax.swing.JFrame;
  import javax.swing.JOptionPane;
  import javax.swing.JPanel;
  
  
  class jp extends JPanel
  {
       int i=0;
  
       {
          setBackground(Color.RED);
       }
  
       @Override
       protected void paintComponent(Graphics g)
       { 
          super.paintComponent(g);
          Color[] c={Color.red,Color.green};
          //To change body of generated methods, choose Tools | Templates.
          g.drawLine(i, i, i+100, i+100);
          i+=50;
       }
  }
  
  public class Trial extends JFrame{
  
     public static void main(String[] args) {
         Trial f=new Trial();
         jp a;
         a=new jp(); 
         System.out.println(a.i);
         f.add(a);
         f.setVisible(true);
         f.setSize(500, 500);
         f.setDefaultCloseOperation(3);
  
         a.repaint();
  
     }
  }
  </code></pre>