title: ImageIcon not getting loaded in Swing
body: <p>The problem is that the image is not getting loaded while I run the following swing program.
  I have a package called "<strong>sWINGPRAC</strong>" inside which I have a JAVA file <em>IconLabelDemo.java</em>. I have ensured that the Image "myIcon.gif" is in the same directory.
  <a href="https://i.stack.imgur.com/U010n.gif" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/U010n.gif" alt="myIcon.gif"></a>
  <strong><em>IconLabelDemo.java</em>.</strong></p>
  
  <pre><code>package sWINGPRAC;
  
  import javax.swing.*;
  import javax.swing.border.Border;
  import java.awt.*;
  
  
  public class IconLabelDemo {
  
          public IconLabelDemo() {
  
              JFrame jfrm = new JFrame("ImageIcon");
              jfrm.getContentPane().setLayout(new GridLayout(4, 1));
              jfrm.setSize(250, 300);
              jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
              ImageIcon img = new ImageIcon("myIcon.gif");
  
              JLabel jlabIcon = new JLabel(img);
  
              JLabel jlabIconTxt = new JLabel("Default iCon and text position",img , SwingConstants.CENTER);
  
              JLabel jlabIconTxt2 = new JLabel("Text left of icon",img,SwingConstants.CENTER);
              jlabIconTxt2.setHorizontalTextPosition(SwingConstants.LEFT);
  
              JLabel jlabIconTxt3 = new JLabel("Text Over ICon",img,SwingConstants.CENTER);
              jlabIconTxt3.setVerticalTextPosition(SwingConstants.TOP);
  
  
              jfrm.add(jlabIcon);
              jfrm.add(jlabIconTxt);
              jfrm.add(jlabIconTxt2);
              jfrm.add(jlabIconTxt3);
  
              jfrm.setVisible(true);
  
          }
          public static void main(String[] args) {
              SwingUtilities.invokeLater(new Runnable() {
  
                  @Override
                  public void run() {
  
                      new IconLabelDemo();
  
                  }
              });
          }
  }
  </code></pre>