title: Jframe JLabel, image refresh only if I resize the window
body: <p>I was trying to do a buffer to display it in a <code>JLabel</code> and use it in a <code>JFrame</code>. I have a problem when I change the image: the image changes only when I resize the window.</p>
  
  <pre><code>package buffer;
  
  import java.awt.Color;
  import java.awt.event.KeyEvent;
  import java.awt.image.BufferedImage;
  import java.io.IOException;
  import java.net.URL;
  import javax.imageio.ImageIO;
  import javax.swing.Icon;
  import javax.swing.ImageIcon;
  
  import javax.swing.JLabel;
  
  
  
  public class principal extends javax.swing.JFrame {
  
  
  private JLabel person=new JLabel();
  public static final int tCuadrito=60;
  private URL url=Buffer.class.getClass().getResource("/imagenes/persona.png");
  private ImageIcon imagenIcon=new ImageIcon();
  private BufferedImage gato=new BufferedImage(120,60,BufferedImage.BITMASK);
  
  public principal() {
      initComponents();
      dibujar();
  }
  
  public void dibujar(){
      try{
  
      gato=ImageIO.read(url);
      }catch(IOException e){
          System.out.print("ERROR imagen no leida: "+e.toString());
      }
  
      imagenIcon.setImage(gato.getSubimage(0, 0, 60, 60));
  
  
  
      person.setBounds(0*tCuadrito, 0*tCuadrito, tCuadrito, tCuadrito);
      person.setVisible(true);
      person.setIcon(imagenIcon);
      contenedor.add(person);
  
  }
  
  
  @SuppressWarnings("unchecked")
  // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
  private void initComponents() {
  
      contenedor = new javax.swing.JPanel();
  
      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
      addKeyListener(new java.awt.event.KeyAdapter() {
          public void keyReleased(java.awt.event.KeyEvent evt) {
              formKeyReleased(evt);
          }
      });
  
      javax.swing.GroupLayout contenedorLayout = new javax.swing.GroupLayout(contenedor);
      contenedor.setLayout(contenedorLayout);
      contenedorLayout.setHorizontalGroup(
          contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGap(0, 400, Short.MAX_VALUE)
      );
      contenedorLayout.setVerticalGroup(
          contenedorLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addGap(0, 300, Short.MAX_VALUE)
      );
  
      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(contenedor, javax.swing.GroupLayout.DEFAULT_SIZE,                           javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      );
      layout.setVerticalGroup(
          layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
          .addComponent(contenedor, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
      );
  
      pack();
  }// &lt;/editor-fold&gt;                                                      
  
  private void formKeyReleased(java.awt.event.KeyEvent evt) {                                 
      switch(evt.getKeyCode()){
          case KeyEvent.VK_RIGHT:
  
              imagen=cat.getSubimage(60, 0, 60, 60);
              imagenIcon.setImage(imagen);
              person.setIcon(imagenIcon);
  
              break;
  
      }
  }                                
  
  
  public static void main(String args[]) {
      try {
          for (javax.swing.UIManager.LookAndFeelInfo info :    javax.swing.UIManager.getInstalledLookAndFeels()) {
              if ("Nimbus".equals(info.getName())) {
                  javax.swing.UIManager.setLookAndFeel(info.getClassName());
                  break;
              }
          }
      } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (InstantiationException ex) {
          java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (IllegalAccessException ex) {
          java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      } catch (javax.swing.UnsupportedLookAndFeelException ex) {
          java.util.logging.Logger.getLogger(principal.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
      }
      //&lt;/editor-fold&gt;
  
      /* Create and display the form */
      java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
              new principal().setVisible(true);
          }
      });
  }
  
  private javax.swing.JPanel contenedor;
  
  }
  </code></pre>