Hi,
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.
Hi Rob,
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")
What does getSystemResource do? And why did you choose that method instead of what Rob suggested in his post?
Bhakta Pradhan
Greenhorn
Joined: Nov 26, 2010
Posts: 22
posted
0
Hi Paul,
Thanks for looking into my issue.Actually I couldn't find ClassLoader.getResource() but I found ClassLoader.getSystemResource(). Hence I used the later. Please suggest me what shall I do?
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.
Bhakta Pradhan
Greenhorn
Joined: Nov 26, 2010
Posts: 22
posted
0
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")
Michael Dunn
Ranch Hand
Joined: Jun 09, 2003
Posts: 4632
posted
0
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 "/".