I have used icons for buttons in my applications.Below code is able to load images when it is run from IDE(eclipse). But when I package everything in a jar file the images are not getting loaded.
Find the attachment to view the jar contents. Can you please let me know what should I do to load those images packaged inside jar file?
I'm using the below code.
Thanks for your response. I changed the code as below.But My program is getting terminated without any error or warning message. Using println statement I found that it's getting terminated once it's trying to execute ClassLoader.getSyatemResource() Please let me know if I'm doing something wrong?
where iconPath is string(image file name eg. "Monitoring.png")
Bhakta Pradhan wrote:Please suggest me what shall I do?
I always use Class.getResource for this, and that was one of Rob's suggestions.
Joined: Nov 26, 2010
Hi I modified my code still images are not getting loaded.
it's not able to find the image .I have also tried only image name getResource("deploy.png")
Joined: Jun 09, 2003
in mthe Swing FAQ you'll find an example of a background image in a panel,
which uses similar code.
add a button to the panel (remove the paintComponent bit - meaning you'll have to handle the 'catch')
use the image to set the button's icon
add the panel to a frame
compile/run, if image displays OK, .jar it
run the .jar, see how you go
When you use Class.getResource, the resource is taken relative to the current class. To use an absolute resource, it must start with a "/". Note that ClassLoader.getResource always uses absolute resource names that should not start with a "/".