0

I am aware the question has been asked before. However, I have tried all the solutions and none seem to work. I have created a simple GUI program using javax.swing, and of course it works perfectly in IntelliJ. However, its consequent jar file has quite a few issues. First and foremost, none of the images even display. I have been importing them as so:

img = new ImageIcon((ImageIO.read(new File("image_name.png"))));

I found a solution suggesting I use:

BufferedImage img = ImageIO.read(new FileInputStream("res/name.png"));

However, not only does it not load in the jar, it takes 5 seconds for the program to even launch in the compiler.

This is getting extremely frustrating, making this an executable. If it's of any use, the JButton components on the jar also don't seem to work. Whenever you click them, they remain pressed but nothing happens further. I understand this isn't loads of info, but I would nontheless appreciate any help you can give. Thanks!

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
ajax992
  • 917
  • 9
  • 16
  • 1
    Assuming that the images are included within the jar then `img = new ImageIcon((ImageIO.read(new File("image_name.png"))))` should be `mg = new ImageIcon((ImageIO.read(getClass().getResource("image_name.png"))))`. The path is relative to the class trying to load the source, you could use `img = new ImageIcon((ImageIO.read(getClass().getResource("/res/image_name.png"))))` to load the image from the `res` directory located from the top of the class path offset – MadProgrammer Apr 25 '16 at 21:49
  • Try to print absolute path of `new File(".")` and you will see where your images are being looked for when you use `new File("image_name.png")`. What you seems to want is reading *resources* which are placed in same jar. If that is the case read http://stackoverflow.com/questions/9864267/load-icon-image-exception – Pshemo Apr 25 '16 at 21:49
  • 1
    Verify if the images are located on the disk or stored in the jar file – MadProgrammer Apr 25 '16 at 21:49

0 Answers0