Haseeb Wali
Haseeb Wali

Reputation: 1171

Project Not showing icons after Executeable jar file

I am running net beans application, when i run it via net beans it is showing icons properly...but when i convert it to executable .exe it is not showing icons..i did a lot of research to solve this problem but everything gone in vain. This is the best method i have saw to get icons dynamically.... My icon heraricy is src/com/idoccsmain/icons/ and all of my icons inside the "icons" folder

  ImageIcon icon = new ImageIcon(Main.Class.getClass().getResource("/com/idoccsmain/icons/"+"add_icon.p‌​ng")

through this line i am getting all of my different icons..can any one suggest any solution for me....?

Upvotes: 1

Views: 3469

Answers (2)

Haseeb Wali
Haseeb Wali

Reputation: 1171

Thanks guys for responses with your help i came up with this... solution put images in Src folder e.g src/icons/ and inside icons folder.enter image description here

Than use this line in netbeans to get your images working......

 ImageIcon icon = new ImageIcon(getClass().getResource("/icons/AnyIconName.png"));

and make sure use this line for each icon.

Upvotes: 3

Ravi
Ravi

Reputation: 31437

For J2ME Application

enter image description here

Check this image carefully, Right Click on project then Properties.

Select Application Descriptor and then select MIDlets

If it is showing anything there, like showing in this picture then edit accordingly.

NOTE : - In the above scenario src/myproject/ where icon and .java exist.

===== UPDATE =====

Desktop based executable jar

Then use, this code

this.getFrame().setIconImage(new imageIcon(getClass().getClassLoader().getResource("add_icon.p‌​ng")));

Note: this line only works if the images are in the root of the jar file. If not, you have to specify the folder on the string:

getResource("yourfolder/add_icon.p‌​ng")

You might also interested for this link to create executable java file and also associate icon to it.

Upvotes: 1

Related Questions