🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: HELP: simple loading gif question

#9470
From: John P. McGrath
Date: Sat, 25 Mar 2000 00:00
32 lines
1537 bytes
On Thu, 23 Mar 2000 15:23:00 -0500, Stephen Legge wrote:

> I'm loading a gif file and placing it in a JButton like so:
> 
> ImageIcon myIcon = new ImageIcon("c:/gifs/mypicture.gif");
> btnConnect.setIcon(myIcon);
> 
> and it works fine.  Now I want to remove the "c:/gifs/" from the path like
> so:
> 
> ImageIcon myIcon = new ImageIcon("mypicture.gif");
> btnConnect.setIcon(myIcon);

Try:
    ImageIcon myIcon = new ImageIcon(
        getClass().getResource("mypicture.gif") );

> But this isn't working.  I tried three things:
>   putting the gif file in the same folder as the .java file
>   putting the gif file in the same folder as the .class file
>   adding the gif file to the JBuilder project
> but nothing worked.

Place the image file in the same folder as the source file for the Java 
class that contains the above code, and add it to your project.  JBuilder 
will automatically copy it to the folder that contains the .class file, 
which is where it needs to be.

-- 
John P. McGrath
<JPMcGrath@fast.net>
<jpm@nscs.fast.net>
Technical Details
Message-ID: <MPG.13461abddce43f35989825@forums.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <8bdtn7$hr12@bornews.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,6000043aed93d9a0
X-Google-Attributes: gid111d45,public
From: John P. McGrath <JPMcGrath@fast.net>
Subject: Re: HELP: simple loading gif question
Date: 2000/03/25
Message-ID: <MPG.13461abddce43f35989825@forums.borland.com>
X-Deja-AN: 602082536
References: <8bdtn7$hr12@bornews.borland.com>
Organization: Another Netscape Collabra Server User
Newsgroups: borland.public.jbuilder.java.swing