-4

This is My code below:

ImageIcon imageIcon10 = new ImageIcon(new ImageIcon(this.getClass().getClassLoader()("image/cake/2.jpg")).getImage().getScaledInstance(150, 150, Image.SCALE_DEFAULT));
Feras Al Sous
  • 1,073
  • 1
  • 12
  • 23
akky
  • 1
  • 1

1 Answers1

0

First step: Put your image in a defined location in your JAR-file. If you put it into the src-folder, maybe your IDE or your build-tool will package it to the JAR automatically. Otherwise check the documentation of your IDE/build-tool, in which location you have to put it.

Second step: Access the file from your program. I assume you put it in the package (the path in your JAR) package1/package2 and the file is called dump.jpg. In that case you call:

setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/package1/package2/dump.jpg")));

getClass().getResource(...) returns an URL for a resource on your classpath. You start the path in the classpath with a '/' and use the complete path/packages to your resource, separated by '/'.

Feras Al Sous
  • 1,073
  • 1
  • 12
  • 23