Article View: borland.public.jbuilder.java.swing
Article #1169Re: Can I make an invisible control?
From: pnichols
Date: Sat, 20 Mar 2004 08:30
Date: Sat, 20 Mar 2004 08:30
58 lines
2944 bytes
2944 bytes
Ted Byers wrote:
>
> "Gillmer J. Derge (TeamB)" <spam@gillmerderge.com> wrote in message
> news:405b28d5$3@newsgroups.borland.com...
>> Ted Byers wrote:
>> > But here is another question about the use of JLabel within the
> designer.
>> > Is it possible to get it to load an image at design time? Without that
>> > capability, it is rather hard to visually place my invisible JLabels.
>>
>> The easiest way is to include the image file in your project. It needs
>> to be an explicit node in the project, not automatically discovered as
>> part of the source tree. For example,
>>
>> 1. Project | Add Files / Packages / Classes...
>> 2. Browse to the file
>>
Short way around this:
(1) Put the images in your /src directory of your project. You can make an
images folder if you wish.
for Instance:
/jbprojects
/myproject
/src/
/com
/yourcompany
/images
image files
/imageclass
ImageDisplay.java
Now in your jbCode do the following
public class ImageDisplay extends JFrame {
JLabel imageLabel= new JLabel();
ImageIcon imgForLabel;
public ImageDisplay() {
}
public void jbInit() throws Exception {
imgforLabel= new
ImageIcon(this.getClass().getResource("../images/TheImage.jpg"));
//other code
}
}
Now switch to the designer. You should see the imgForLabel listed for
setIcon. If you don't compile, and retry to set the Icon for the Label. It
should be there now (it will copy the images file to the classes folder on
compile).
Technical Details
Message-ID:
<405bfd17@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.ash.giganews.com!nntp.giganews.com!ngpeer.news.aol.com!feed2.newsreader.com!newsreader.com!newshosting.com!nx01.iad01.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<405b119a$1@newsgroups.borland.com> <405b1413$1@newsgroups.borland.com> <405b1da8$1@newsgroups.borland.com> <405b1f78$1@newsgroups.borland.com> <405b2349$1@newsgroups.borland.com> <405b28d5$3@newsgroups.borland.com> <405b55d4$2@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 111d45,713e84ee88d10114 X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-03-20 00:30:08 PST Message-ID: <405bfd17@newsgroups.borland.com> From: pnichols <paul@comp.net> Subject: Re: Can I make an invisible control? Newsgroups: borland.public.jbuilder.java.swing Reply-To: paul@comp.net Mail-Copies-To: paul@comp.net Date: Sat, 20 Mar 2004 03:30:14 -0500 References: <405b119a$1@newsgroups.borland.com> <405b1413$1@newsgroups.borland.com> <405b1da8$1@newsgroups.borland.com> <405b1f78$1@newsgroups.borland.com> <405b2349$1@newsgroups.borland.com> <405b28d5$3@newsgroups.borland.com> <405b55d4$2@newsgroups.borland.com> Lines: 58 Organization: clc User-Agent: KNode/0.7.6 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit NNTP-Posting-Host: 68.71.188.25 X-Trace: newsgroups.borland.com 1079770391 68.71.188.25 (20 Mar 2004 00:13:11 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!border1.nntp.ash.giganews.com!nntp.giganews.com!ngpeer.news.aol.com!feed2.newsreader.com!newsreader.com!newshosting.com!nx01.iad01.newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail