title: java swing resize ImageIcon according to jLabel
body: <p>i am a new programmer here and i have something to ask, i have browse a picture into my GUI (and set the path in text box also)which displays on a Label, but the label dimension is set only 100,100 while the picture is much bigger so when i open/display it into the label it get cropped , is there anyway to make it auto resize to the label size? below is my logic code on browse button and open dialog box 
  please any one tell me where i am wrong..</p>
  
  <pre><code>public class ImagePath extends javax.swing.JFrame {
      private JPanel contentPane;
  
      JLabel jLabel1;
      String s2;
      File targetFile;
      BufferedImage targetImg;
  
      public ImagePath() {
          initComponents();
      }
  
      private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
  
          JFileChooser jFileChooser1 = new JFileChooser();
  
          int state = jFileChooser1.showOpenDialog(new JFrame());
  
          jTextField1.setText("");
          if (state == JFileChooser.APPROVE_OPTION) {
              JOptionPane.showMessageDialog(new JFrame(), "hii");
              File file = jFileChooser1.getSelectedFile();
              s2 = file.toString();
              jTextField1.setText(s2);
              jLabel1 = new JLabel();
              jLabel1.setName(s2);
              jLabel1.setLocation(50, 50);
              jLabel1.setSize(300, 300);
              add(jLabel1);
              BufferedImage bi1;
  
              try {
                  bi1 = ImageIO.read(file);
                  ImageIcon icon1 = new ImageIcon(bi1);
                  jLabel1.setIcon(icon1);
  
                  Image img = icon1.getImage();
                  ImageIcon icon = new ImageIcon(file.getPath());
                  Image scaleImage = icon.getImage().getScaledInstance(28, 28, Image.SCALE_DEFAULT);
  
                  repaint();
                  pack();
  
              } catch (Exception e) {
                  System.out.println(e);
              }
          } else if (state == JFileChooser.CANCEL_OPTION) {
              JOptionPane.showMessageDialog(new JFrame(), "Canceled");
          }
  
      }
  
  }
  </code></pre>