title: Override paint(graphics g) Java
body: <p>I have a little issue with my GUI in NetBeans.  I draw images (dots) when a user clics in a JPanel at the mouse clic location.  This part works just fine.  I store each image locations in two different ArrayList that contains the X location and Y location.  Now what I want to do is to delete the latest image drawn in the Panel after a button is clicked.  So what I did is remove the last index of both ArrayList, and then call repaint() to draw all the images from the locations in both X and Y ArrayList (code below).  </p>
  
  <p>What is weird is that I need to resize the GUI (put it in full screen or just change its' size) in order for the drawn images to show up again in the JPanel otherwise, the panel remains empty.</p>
  
  <p>Here's the parts of code that are affected : </p>
  
  <pre><code>public void paint(Graphics g) {
  
      super.paint(g);
      for(int i=0;i&lt;=listePointsX.size()-1;i++) {
          try{
              BufferedImage icon = ImageIO.read(getClass().getResourceAsStream("/myimage.png"));
              Graphics graphe = jPanel1.getGraphics();
              graphe.setColor(Color.BLACK);
              graphe.drawImage(icon, this.listePointsX.get(i),this.listePointsY.get(i), rootPane);
          }catch(Exception e1){
  
          }
      }
  
  private void jButtonUndoActionPerformed(java.awt.event.ActionEvent evt) {                                            
      if(listePointsX.size()&gt;0){
          int lastObject= listePointsX.size();
          listePointsX.remove(lastObject-1);
          listePointsY.remove(lastObject-1);
          jPanel1.repaint();         
      }
      else{
  
      }
  
  
  }   
  </code></pre>
  
  <p>Any idea what I need to do to some kind of "refresh" the whole thing?  Am I doing something wrong?  Tried searching about that but did not find anyting...  </p>