🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #9277

Re: Loading images from jar file

#9277
From: Steve Horsley
Date: Wed, 19 Apr 2000 00:00
27 lines
1428 bytes
Funnily enough, I got this working last week:

    URL url =
ClassLoader.getSystemClassLoader().getResource("mypackage/smiley.jpg");
    //System.out.println("url = " + url);
    if(url != null) {
        jframe.setIconImage(jframe.getToolkit().getImage(url));
    }

One oddity, presumably to do with security...
If I put the jpg file in the root of the jar file, it did not work.
I had to put the jpg file in the same directory as the class that was
doing the resource loading (the mypackage subdirectory in this case).

Hope this helps.
Steve.

Richard wrote:
> 
> I want to distribute my app in a jar file including the images, but
> creating the ImageIcon only seems to work if I specify an absolute
> path.
> 
> How can I specify that the image is in the jar file or use a relative
> path to load the image ?
> 
> Richard
Technical Details
Message-ID: <38FDB38D.161605C7@cwcom.co.uk>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <38fd824d.4293483@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,ec9795bc13a1381d
X-Google-Attributes: gid111d45,public
From: Steve Horsley <steve.horsley@cwcom.co.uk>
Subject: Re: Loading images from jar file
Date: 2000/04/19
Message-ID: <38FDB38D.161605C7@cwcom.co.uk>
X-Deja-AN: 613129352
Content-Transfer-Encoding: 7bit
References: <38fd824d.4293483@newsgroups.borland.com>
X-Accept-Language: en
Content-Type: text/plain; charset=us-ascii
X-Trace: 19 Apr 2000 06:16:19 -0800, 194.200.13.1
MIME-Version: 1.0
Newsgroups: borland.public.jbuilder.java.swing