🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Problem getting an image to dispaly in JLabel

#1078
From: Greg Hamer
Date: Mon, 22 Mar 2004 18:46
51 lines
2985 bytes
I would select the image file from the icon property drop down list and make
sure that the project is compiled. The way you are specifying it below, you
are looking for a file relative to the working directory.  Reading files is
a no no  in an applet, but that is not why the designer is not showing the
image. It just cannot find it when you speicify it that way. (JBuilder's
working directory is not your projects working directory). If you put the
image file in the same directory as the java file that will be using it, and
add the file to the project, the designer will be able to reference it with
an URL releative the the class that is using it, and be able to find it.

"Ted Byers" <r.ted.byers@sympatico.ca> wrote in message
news:405b5ea9$1@newsgroups.borland.com...
> Here is the initialization code for the applet.:
>
>   //Component initialization
>   private void jbInit() throws Exception {
>     component1 = Box.createGlue();
>     jLabel1.setDebugGraphicsOptions(0);
>     jLabel1.setMinimumSize(new Dimension(700, 500));
>     jLabel1.setIconTextGap(4);
>     jLabel1.setText("");
>     Icon icon = new ImageIcon( "sunset.jpg" );
>     jLabel1.setIcon(icon);
>     xYLayout1.setWidth(800);
>     xYLayout1.setHeight(600);
>     this.setLayout(xYLayout1);
>     this.add(jLabel1,  new XYConstraints(17, 23, 753, 548));
>   }
>
> Although I added several jpeg and gif files to the project, and they
appear
> in the dropdown list for the icon of jLabel1, selecting one of them does
> virtually nothing.  So I added two lines of code:
>
>     Icon icon = new ImageIcon( "sunset.jpg" );
>     jLabel1.setIcon(icon);
>
> Still no joy.  It seems that no matter what I try, I can't get these
images
> to display within the applet.  (NB: When the project is done, the image
will
> need to go into the same jar as the applet.)
>
> What do I need to do to get this working (both from within JBuilder
> 9(personal) and from within a jar)?
>
> Thanks,
>
> Ted
>
>
Technical Details
Message-ID: <405f3446$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newshosting.com!nx02.iad01.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <405b5ea9$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,f4a0c6583761a428
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2004-03-22 11:02:28 PST
From: "Greg Hamer" <ghamer@dslextreme.com>
Newsgroups: borland.public.jbuilder.java.swing
References: <405b5ea9$1@newsgroups.borland.com>
Subject: Re: Problem getting an image to dispaly in JLabel
Date: Mon, 22 Mar 2004 10:46:59 -0800
Lines: 53
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 24.52.242.126
Message-ID: <405f3446$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1079981126 24.52.242.126 (22 Mar 2004 10:45:26 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news2.google.com!news.maxwell.syr.edu!newshosting.com!nx02.iad01.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail