Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / August 2006

Tip: Looking for answers? Try searching our database.

ImageIcon to Image in a jar file?

Thread view: 
tiewknvc9 - 14 Aug 2006 22:17 GMT
hi!

I am trying to get an image from an Imageicon within a jar file.

Outside of the jar file this is pretty easy,
myImage = myImageIcon.getImage();

to get from a string to an image obviously we do the following
URL url = Image.class.getResource(strFile);

that is not what I am asking though...

My function receives an ImageIcon, and I have to convert it to an Image
within the jar file...  

Any ideas?
tiewknvc9 - 14 Aug 2006 22:35 GMT
I tried this:

myImage = ImageIO.read(getClass().getResource(myImageIcon.toString()));

but it doesnt work because the toString method breaks in the jars
execution...

> hi!
>
[quoted text clipped - 12 lines]
>
> Any ideas?
tiewknvc9 - 14 Aug 2006 22:36 GMT
I also tried simply

myImage = myImageIcon.getImage();

but that causes a crash too...

> hi!
>
[quoted text clipped - 12 lines]
>
> Any ideas?
danharrisandrews@gmail.com - 14 Aug 2006 22:41 GMT
Hi,

I always use the resource for a jar or for files. First make sure that
you copy your image files to your compiled sources location and then
reference your images like this. Always reference your resources that
way if you are going to eventually distribute them in a jar and it will
save to time in the end.

String location = "my/package/for/images/myimage.gif";
ImageIcon icon = null;
URL iconURL = SomeClassInJar.class.getClassLoader().getResource(
       location);
if (iconURL != null) {
   icon = new ImageIcon(iconURL);
}

Better yet, centralize this code in an ImageUtilities class to save
more time.

Cheers,

Dan Andrews

- - - - - - - - - - - - - - - - - - - - - - - -
Ansir Development Limited www.ansir.ca
- - - - - - - - - - - - - - - - - - - - - - - -

> hi!
>
[quoted text clipped - 12 lines]
>
> Any ideas?


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.