🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.api
Article #1186

Re: How to open an image?

#1186
From: H�kan Eriksson
Date: Wed, 24 Apr 2002 12:34
69 lines
2608 bytes
Hi!

You're a bit off.... I assume that what you want to do is not just to load
the image but to display it as well, right? You can easily display the image
by putting it on a JLabel.

So to load it:
JLabel imageLabel = new JLabel(new
ImageIcon(this.getClass.getResource("images/imagename.gif")));

To display the image, just add imageLabel to a GUI.

The path "images/imagename.gif" assumes that you have put the image file in
a directory called "images" located within the package where you have your
class file. So if your package for the class file is "com.acme.app", put
your image in "com/acme/app/images/." and remember to include that directory
into the classpath. Better yet, create one JAR file that contains your
classes and images.

Hope this helps
H�kan


"Grzegorz. : 3Man: .Wolny" <g_wolny@o2.pl> wrote in message
news:a9j6uq$r4i$1@news.tpi.pl...
> Hi!
>
> I have a problem with opening an image in JBuilder 4 Foundation. I don't
> know how schould the opening procedure look like. I know how to begin but
> what next?
>
> void openFile(String fileName)
>
> {
>
>     try
>
>     {
>
>         File file = new File(fileName);
>
>         int size = (int)file.length();
>
>         //I don't know what schould I write next...
>
>     }
>
>     in.close();
>
>     statusBar.setText("Opened "+fileName);
>
> }
>
> catch (IOException e)
>
> {
>
>     statusBar.setText("Error opening "+fileName);
>
> }
>
> }
>
> Could someone help me with this?
>
> Grzegorz Wolny
>
>
>
Technical Details
Message-ID: <HDxx8.2813$p56.570886@newsb.telia.net>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!supernews.com!skynet.be!skynet.be!news.algonet.se!algonet!news-stob.telia.net!news-sto.telia.net!masternews.telia.net.!newsb.telia.net.POSTED!not-for-mail
References: <a9j6uq$r4i$1@news.tpi.pl>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 1089d0,e3303bee28f8e3dc
X-Google-Attributes: gid1089d0,public
X-Google-ArrivalTime: 2002-04-24 05:36:29 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-03!supernews.com!skynet.be!skynet.be!news.algonet.se!algonet!news-stob.telia.net!news-sto.telia.net!masternews.telia.net.!newsb.telia.net.POSTED!not-for-mail
From: "H�kan Eriksson" <hakan.eriksson@trollhattan.mail.telia.com>
Newsgroups: borland.public.jbuilder.java.api
References: <a9j6uq$r4i$1@news.tpi.pl>
Subject: Re: How to open an image?
Lines: 71
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2600.0000
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000
Message-ID: <HDxx8.2813$p56.570886@newsb.telia.net>
Date: Wed, 24 Apr 2002 12:34:47 GMT
NNTP-Posting-Host: 62.20.170.41
X-Complaints-To: abuse@telia.com
X-Trace: newsb.telia.net 1019651687 62.20.170.41 (Wed, 24 Apr 2002 14:34:47 CEST)
NNTP-Posting-Date: Wed, 24 Apr 2002 14:34:47 CEST
Organization: Telia Internet