Article View: borland.public.jbuilder.java.language
Article #7598Re: How-to keep images in resources(?) in a java application for use in e.g. menus?
From: Ken Warner
Date: Tue, 12 Jun 2001 16:55
Date: Tue, 12 Jun 2001 16:55
52 lines
2887 bytes
2887 bytes
Hi Thomas,
This question should be in a FAQ somewhere...I can't find it there either.
I'm assuming that you are using Java 2.
The way I do this is to:
1) Put the location of the image into the source path using the Project Properties
dialog. You can have multiple source folders in the source path.
2) Then add the image file to the project using the Project -> Add Files/Packages
You should then be able to see the icon in the properties panel for the JComponent
that you want to display an ImageIcon.
3) Click on the icon property for that component and you *SHOULD* see the
icon as a menu item.
4) Select the icon and you should see something like the following in your code:
playButton.setIcon(new ImageIcon(new java.net.URL("file:///D:/JBuilder/projects/JSound/images/Play24.gif")));
4a) If you want to jar the gif file you have to use the Archive Builder to add the gif file as a class or file.
5) Now here is the tricky part -- if you want to jar the applet or app and you want the icon
to be accessed as a resource you have to do something that I haven't figured out how to do yet.
There is a way to make JBuilder produce code like:
refreshJButton.setIcon(new ImageIcon(JCameraWare.class.getResource("Refresh24.gif")));
Which is what you really want if you are going to jar your app/applet. But I only know
how to produce this code by hand editing.
Does anyone in "TeamB" know how to make JBuilder produce the getResource() code???
Thomas Schulz wrote:
> E.g. for this:
>
> setIconImage(Toolkit.getDefaultToolkit().createImage(FrameEditor.class.getRe
> source("[Back16.gif]")));
>
> I tryed to inlclude a file called Back16.gif in my project.. I guess that
> doesn't do the trick... I suspect I'll need to make a Jar file or something?
> Well.. But I would like to see it design time too if possible?
> What to do, where to read, anyone knows (tryed google search on resources
> and java)?
>
> Regards
> Thomas Schulz
--
Ken Warner
Technical Details
Message-ID:
<3B264973.55C7445B@cts.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnewsReferences:
<3b1a26d5$1_1@dnews>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f74b3,9cd5cec6235717ef X-Google-Attributes: gidf74b3,public X-Google-ArrivalTime: 2001-06-12 10:09:23 PST Message-ID: <3B264973.55C7445B@cts.com> Date: Tue, 12 Jun 2001 09:55:15 -0700 From: Ken Warner <kwarner@cts.com> X-Mailer: Mozilla 4.73 [en] (WinNT; U) X-Accept-Language: en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.language Subject: Re: How-to keep images in resources(?) in a java application for use in e.g. menus? References: <3b1a26d5$1_1@dnews> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 216.120.8.37 X-Trace: dnews 992364942 216.120.8.37 (12 Jun 2001 09:55:42 -0700) Lines: 54 Path: arc1-ca.pugleaf.net!archiver1.google.com!newsfeed.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!hub.org!hub.org!PeerFeed.KWeb.on.ca!dnews