title: Load image in Jframe using jpanel variable
body: <p>i am using netbeans to built a image viewer using swings.. using the netbeans swing builder GUI i got the following code, i have put a jpanel in a parent jframe. all that i want to do as of for now is open an image in the jpanel and add it to jframe</p>
  
  <p>here is the code:</p>
  
  <pre><code>/*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package javaapplication1;
  
  import java.awt.Component;
  import java.awt.Dimension;
  import java.awt.Graphics;
  import java.awt.event.WindowAdapter;
  import java.awt.event.WindowEvent;
  import java.awt.image.BufferedImage;
  import java.io.File;
  import java.io.IOException;
  import java.util.logging.Level;
  import java.util.logging.Logger;
  import javax.imageio.ImageIO;
  import javax.swing.JPanel;
  
  /**
   *
   * @author Tempo
   */
  public class NewJFrame extends javax.swing.JFrame {
  
      /**
       * Creates new form NewJFrame
       */
      public NewJFrame() throws IOException {
          initComponents();
          final BufferedImage gray_img=ImageIO.read(new File("C:/Users/Tempo/Pictures/sucess.png"));
                      this.setBounds(0, 0, gray_img.getWidth(), gray_img.getHeight());
                      this.jPanel1 =new JPanel(){
                      @Override
                      public void paint(Graphics g) {
                              // TODO Auto-generated method stub
                              super.paint(g);
                              g.drawImage(gray_img, 0, 0, null);
                      }
  
                                      };
                      this.add(jPanel1);
  
      }
  
      /**
       * This method is called from within the constructor to initialize the form.
       * WARNING: Do NOT modify this code. The content of this method is always
       * regenerated by the Form Editor.
       */
      @SuppressWarnings("unchecked")
      // &lt;editor-fold defaultstate="collapsed" desc="Generated Code"&gt;                          
      private void initComponents() {
  
          jPanel1 = new javax.swing.JPanel();
  
          setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
  
          javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
          jPanel1.setLayout(jPanel1Layout);
          jPanel1Layout.setHorizontalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 440, Short.MAX_VALUE)
          );
          jPanel1Layout.setVerticalGroup(
              jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGap(0, 276, Short.MAX_VALUE)
          );
  
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
          getContentPane().setLayout(layout);
          layout.setHorizontalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addContainerGap()
                  .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addContainerGap(153, Short.MAX_VALUE))
          );
          layout.setVerticalGroup(
              layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
              .addGroup(layout.createSequentialGroup()
                  .addGap(21, 21, 21)
                  .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                  .addContainerGap())
          );
  
          pack();
      }// &lt;/editor-fold&gt;                        
  
      /**
       * @param args the command line arguments
       */
      public static void main(String args[]) {
          /*
           * Set the Nimbus look and feel
           */
          //&lt;editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "&gt;
          /*
           * If Nimbus (introduced in Java SE 6) is not available, stay with the
           * default look and feel. For details see
           * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
           */
          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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (InstantiationException ex) {
              java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (IllegalAccessException ex) {
              java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
          } catch (javax.swing.UnsupportedLookAndFeelException ex) {
              java.util.logging.Logger.getLogger(NewJFrame.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() {
                  try {
                      NewJFrame frame=new NewJFrame();
  //                    frame.setPreferredSize(new Dimension(800,600));
  //                    frame.setMinimumSize(new Dimension(200,400));
  
  
                      frame.setVisible(true);
                  } catch (IOException ex) {
                      Logger.getLogger(NewJFrame.class.getName()).log(Level.SEVERE, null, ex);
                  }
  
              }
          });
      }
      // Variables declaration - do not modify                     
      private javax.swing.JPanel jPanel1;
      // End of variables declaration                   
  }
  </code></pre>
  
  <p>when the file is run, it only displays a blank jframe with no image/(Jpanel) in it!</p>