title: Strange jpanel paint
body: <p>here is my class</p>
  
  <pre><code>public class Grid extends JPanel{
      public Grid(Dimension dim){
          this.dim = dim;
          step = 0.02;
          this.setSize(dim);
          this.setLocation(0, 0);
      }
  
      @Override
      public void paint(Graphics g){
          for(int i=-1; i&lt;this.getHeight(); i+=this.getHeight()*step){
              g.drawLine(0, i, this.getWidth(), i);
          }
          for(int i=-1; i&lt;this.getWidth(); i+=this.getWidth()*step){
              g.drawLine(i, 0, i, this.getHeight());
          }
      }
  }
  </code></pre>
  
  <p>(I skipped the definition of class variables)</p>
  
  <p>I add this class in another JPanel like this</p>
  
  <pre><code>Grid grid = new Grid(dim);
  parentPanel.add(grid);
  </code></pre>
  
  <p>By default, the grid is hidden ( <code>grid.hide();</code> ) so my jFrame looks something like this:
  <a href="https://i.stack.imgur.com/pelyo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pelyo.png" alt="enter image description here"></a></p>
  
  <p>where the "blue" area is the parentPanel and the "orange" area is a JPanel with buttons. The problem is that when I press the grid button, I get the following result:<a href="https://i.stack.imgur.com/wSzpA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wSzpA.png" alt="enter image description here"></a></p>
  
  <p>where the grid lines are ok, but I get also this orange box which I do not know why is there.</p>
  
  <p>Any ideas?</p>