🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: HELP: simple loading gif question

#9484
From: Stephen Legge
Date: Mon, 27 Mar 2000 00:00
44 lines
2099 bytes
"John P. McGrath" <JPMcGrath@fast.net> wrote in message
news:MPG.13461abddce43f35989825@forums.borland.com...
> 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") );

This doesn't work -- getClass().getResource("mypicture.gif") always returns
null.  I'm using JBuilder 3.5 (with 1.2.2), does this only work in 1.1.x?

> > 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.

It doesn't appear to be working.  Do you have any other suggestions?

> --
> John P. McGrath
> <JPMcGrath@fast.net>
> <jpm@nscs.fast.net>

Stephen Legge
Ottawa, Canada
Technical Details
Message-ID: <8bobu5$n2p4@bornews.borland.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <8bdtn7$hr12@bornews.borland.com> <MPG.13461abddce43f35989825@forums.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: "Stephen Legge" <stephen@cryptocard.com>
Subject: Re: HELP: simple loading gif question
Date: 2000/03/27
Message-ID: <8bobu5$n2p4@bornews.borland.com>
X-Deja-AN: 603076033
References: <8bdtn7$hr12@bornews.borland.com> <MPG.13461abddce43f35989825@forums.borland.com>
X-Priority: 3
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6700
Organization: Another Netscape Collabra Server User
X-MSMail-Priority: Normal
Newsgroups: borland.public.jbuilder.java.swing