You can do this:
 
   ImageIcon imageIcon = new ImageIcon(new URL(getCodeBase(),"cluster.gif"));
 
if the image is in a package ...

   ImageIcon imageIcon = new ImageIcon(new URL(getCodeBase(),"package/cluster.gif"));
 
I hope this can help. :-)
 
 
-------------------------------------------------------------
                 Jose Luis Rando Calvo
       Area de Investigaci�n y Desarrollo
       Estudio Inform�tica Software S.L.U.
             � � ----==== Grupo EI ====---- � �
-------------------------------------------------------------

>>> "Farwell, Paul" <[EMAIL PROTECTED]> 05/02 9:03  >>>
Try this:

   public static ImageIcon getImage(String imageKey) {
      ImageIcon img = null;
      URL imgURL = resource.getClass().getResource(imageKey);
      if (null == imgURL)
         throw new NullPointerException("Missing image for " + imageKey);
      img = new ImageIcon(Toolkit.getDefaultToolkit().createImage(imgURL));
      return img;
   }

The resource instance is a do-nothing subclass of Object. I could have made
a simple call to this.getClass().getResource() but unfortunately my getImage
method needs to be static.

-----Original Message-----
From: Ajit Bhingarkar [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 02, 2001 2:57 PM
To: Ravi Prakash
Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
Subject: Re: how to get *.gif files from jar file


You need to use getResource() to get gifs ..


Ravi Prakash wrote:
>
> Hi,
>
> I am using applet and the classes are put in a jar file.  In the jar
> file there are gif files.
> I have to display in the applet.
>
> i am using follwing syntax
>
> ImageIcon imageIcon = getImageIcon("cluster.gif");
> if (imageIcon != null) clusterImageJLabel.setIcon(imageIcon);
>
> I am not getting the image to be displayed in the applet.
>
> any suggestion please...
> raviprakash
>
> _______________________________________________
> Advanced-swing mailing list
> [EMAIL PROTECTED]
> http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing
_______________________________________________
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing

Reply via email to