Win a copy of Bad Programming Practices 101 (e-book) this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Icon image is not visible by directly opening jar file  RSS feed

 
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello friends,

i have made one swing application and inserted icon image into it using netbeans ide.
when i open my class using netbeans than icon is displaying properly but opening by directly clicking an jar file it is not showing.

i have pasted my code here.


Why it is?
 
Marshal
Posts: 59404
187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Maybe the location of the image file is wrong. We need more details, including the locations of the image in the NetBeans folders and in the .jar. And why are you not using Class#forName#getResource or similar?
 
Bartender
Posts: 11445
18
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

SunilK Chauhan wrote:
when i open my class using netbeans than icon is displaying properly but opening by directly clicking an jar file it is not showing.



Resources from within a jar need to be accessed via the Class#getResource() or Class#getResourceAsStream()

More about it here
https://docs.oracle.com/javase/8/docs/technotes/guides/lang/resources.html
 
SunilK Chauhan
Ranch Hand
Posts: 89
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes guys.

It's working. It's the issue of image fetching properly from the resources. Now I can view the image from jar file also.
Thank you guys.
 
No matter. Try again. Fail again. Fail better. This time, do it with this tiny ad:
Why should you try IntelliJ IDEA ?
https://coderanch.com/wiki/696337/IntelliJ-IDEA
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!