Re: Loading icons out of a jar file

Frank Meissner <[email protected]> Fri, 17 Sep 2004 21:09:11 +0200
Newsgroups gmane.comp.embedded.carlsbad-cubes
Message-ID <[email protected]>
Mathias Payer wrote:
> Hi List!
> 
> First of all: Thanks Frank for your input!
> 
> 
>>there is no need to render the xml file like this. Just put your 
>>StartUp.xml in your classpath and write it like this:
>>Container container = swix.render("StartUp.xml");
> 
> This worked fine, thanks

At least some positive, response, thank You very much :-)

> 
> 
>>(I usally have a separated "resource" folder containing my 
>>SwixML-XML-files, icons and the like. This resource folder is put in
>>the classpath.)
> 
> I'm putting everyhting into one JAR-File, the application, the xml files
> and the icons (images), because this application will not be too large.

Yes, I do this similar, it makes a easier deployment.

> 
> Now I'v got everything in the JAR File, something is done but the image
> is not displayed!
> 
> --SNIP--
> <button id="btn_EMail" mnemonic="mn_btn_EMail" name="btn_EMail"
> Action="SwitchFunction" ActionCommand="Frame_EMail" Icon="img_EMail"
> FocusPainted="false" ToolTipText="ttt_btn_EMail"/>
> 
> <button id="btn_Calendar" mnemonic="mn_btn_Calendar" name="btn_Calendar"
> Action="SwitchFunction" ActionCommand="Frame_Calendar"
> Icon="yggdrasil/icons/test.gif" ToolTipText="ttt_btn_Calendar"
> enabled="true" BorderPainted="true" FocusPainted="false"
> size="24,24"/>
> --SNAP---- 
> 
> Both buttons acces the same gif-file. The first one is with i18n and the
> second without.

What do you mean by "The first one is with i18n and the second without"? 
  You have a property file with
img_EMail=yggdrasil/icons/test.gif
? Do you mention this property file in your top level container? 
Something like bundle="path-to-my-properties-file-in-the-jar-file"? 
Perhaps you can have a closer look at this? There must not be more than 
one bundle-attribute and it must be mentioned in the top level container 
(your outmost frame, dialog, ...). Try to translate your texts which you 
may already did looking at the name attributes you state...

> 
> I think the image gets loaded as there is some space left for the image
> and you can see the border of the image when the button is selected.

*That* indicates the image does not load correctly. Try to put a 
non-existent image name in and see if the behaviour changes...

> 
> After a lot of testing I tried the following:
> 
> --SNIP--
> ImageIcon img = new
> ImageIcon(swix.getLocalizer().getClassLoader().getResource("yggdrasil/i
> cons/test.gif"));
> 
> System.out.println(img+"\n"+img.getIconWidth()+" "+img.getIconHeight());
> 
> btn_Addressbook.setIcon(img);
> 
> btn_Addressbook.validate();
> 
> MainUIFrame.validate();
> --SNAP--
> 
> I set the Image of a Button manually. And I discover the same behavior
> like the buttons in the XML File.
> The Output on the console is the following:
> 
> --SNIP--
> jar:file:/home/gannimo/Verschiedenes/Programmierung/Yggdrasil/build/ygg
> drasil.jar!/yggdrasil/icons/test.gif
> 
> 16 16
> --SNAP--
> 
> This tells me that the image is found and can be accessed.

Yes, by using the direct path as you have done in your second button 
image, which also works. It seems to be a problem with i18n and the 
image name.

> 
> But why isn't it displayed?
> I valled validate to repaint the screen and display the changes.

No, there is no need to do that here.

> 
> I also tried the localization and other examples, there all icons work,
> but they are not loaded from a jar-file?

IMHO the icons there are referenced by the direct path without having a 
resource bundle tranlate them first. The jar file is not the problem I'm 
sure...

> 
> Has anybody any idea what I'm doing wrong?

Put the image path direct in there.