title: Java PaintComponent size and position in a subclass of an abstract class that extends Jpanel
body: <p>I'm building a simple chess game and am stuck on trying to paint drawings on a Panel</p>
  
  <p>I have a board ready and on the board there are panels. those panels are 70x70px and next thing i want to do is use THAT ENTIRE SURFACE to draw chess pieces. </p>
  
  <p>i made an abstract class Pieces that extends JPanel.</p>
  
  <pre><code>public abstract class Piece extends JPanel
  </code></pre>
  
  <p>One of the pieces is ofcourse, a Pawn : </p>
  
  <pre><code>public class Pawn extends Piece
  </code></pre>
  
  <p>in the Pawn class I have paint component : </p>
  
  <pre><code>public void paintComponent(Graphics g)
  {
      super.paintComponent(g);
      int w = getWidth();
      int h = getHeight();
      g.setColor(Color.GREEN);
      g.fillOval(0, 0, w, h);
      System.out.println("height:"+h+" width:"+w);
  }
  </code></pre>
  
  <p>This does not seem to work. the output prints height = 10px and width = 10px; .... but it is suposed to be 70px and 70px. I also see the green oval painted inside a 10x10 square, which is inside my Panel...</p>
  
  <p>I tried a setSize(70,70) which does not realy do the trick... 
  I also tried SetPreferredSize but well It did not really work out either. 
  I really want to keep my abstract class and subclasses... </p>
  
  <p>@@@ EDIT @@@
  I've used setPreferredSize again and I can now actually draw my green circle on the Jpanel. but an error remains as in it is not the whole surface of the Jpanel Used... there remains a gap at the top , a screenshot:<br> <img src="https://i.stack.imgur.com/ozR8O.png" alt="http://imgur.com/INVj4"></p>