0

I have made a software in core java and this software will be executed on PC so I have made jar of my software and executed jar on my pc. jar is executing properly but as i have used images on jbutton so those images are not getting loaded when i execute jar. jbutton and images not shown and creating problem for my whole software... as when i am loading images on jbutton is like this...

public BufferedImage loadImage(String fileName){

BufferedImage buff = null;
try {
    buff = ImageIO.read(getClass().getResourceAsStream(fileName));
} catch (IOException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
    return null;
}
return buff;

}

     btn.setIcon(new ImageIcon(loadImage("/images/index.jpeg")));

kindly help..

Vishnudev K
  • 2,874
  • 3
  • 27
  • 42

2 Answers2

0

The answer (and the links provided in it) to my question can i use url... should be helpful

Community
  • 1
  • 1
BendyMan
  • 301
  • 1
  • 3
  • 8
0

Try to fill out the path name completely to the image file

MyClass.class.getProtectionDomain().getCodeSource().getLocation().getPath() + "/images/index.jpeg";

Replace MyClass with your Class name. This line of code finds the path to the location of your jar file.

fulp
  • 28
  • 1
  • 7