0

I am adding image in label and label in JPanel. It doesn't show any error but doesn't load image too. Cant see any problem. images folder are placed in folder where java file is placed.Any help would be appreciated.

String path=".\\images\\1.jpg";
ImageIcon imgThisImg = new ImageIcon(path);
lblIcon.setIcon(imgThisImg);
lblIcon.setBounds(0,0,getX(),getY());
boardPanel.add(lblIcon);
user3768904
  • 261
  • 3
  • 15

1 Answers1

1

I believe the issue is that the path provided is relative to the working directory. Instead of using a relative path, use an absolute path, starting with the working directory.

String path = System.getProperty("user.dir") + "/images/1.jpg";

Once you do that, print it, and I'm sure you'll find that it's not pointing to where you think it is.

Andy Senn
  • 649
  • 5
  • 13
  • Thanks A lot! :) I was using system.getProperty but like String path = System.getProperty("user.dir") + "/images/1.jpg"; – user3768904 Feb 19 '15 at 15:47