Article View: borland.public.jbuilder.java.api
Article #319Re: Problems with loading & displaying a picture
From: Paul Furbacher
Date: Mon, 02 Feb 2004 20:45
Date: Mon, 02 Feb 2004 20:45
74 lines
3310 bytes
3310 bytes
Andreas Koch wrote:
> Unfortunately i can't compile the method using Classloader.
> Seems JPanel has no getClassLoader, and drawImage(I,int,int,
> int,int,<null type>) doesn't take ImageIcons.
For some reason, this topic on how to load images
has come up a lot recently. Please consult the
archives for a rather lengthy message on this issue.
Go to www.tamaracka.com and use the exact keywords
(including the circumflex):
^jbuilder furbacher images directories
That thread does indeed apply to your case.
Make sure that you adopt the proper method
of packaging your images. They must be on
the classpath. The best place to locate
them in your classpath/package structure is
relative to the package/directory of the
class which is going to load the images.
For instance, if you have the package and class
org.myorg.views.MyPanel
and MyPanel uses some images (e.g., image1.png
and image2.png), the best packaging/structuring
of these images is
// given a root folder for your project, MyProject
.../MyProject
/bak
/doc
/classes
/src
/org
/myorg
/views
- MyPanel.java
/images
- image1.png
- image2.png
Given this packaging/directory structure, you
would get your Image using
URL url = MyPanel.class.getResource("images/image1.png");
// with the URL, you can now get your ImageIcon.
Also, it might be a good idea to drill down into
the code for ImageIcon, flip to the "Doc" tab
in the Editor, and click on the "How to Use Icons"
link in the JavaDoc header comments. Study very
thoroughly the "Loading Images Using getResource"
section of that tutorial. Understanding this is
absolutely essential.
--
Paul Furbacher (TeamB)
Save time, search the archives:
http://www.borland.com/newsgroups/ngsearch.html
Is it in Joi Ellis's Faq-O-Matic?
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Finally, please send responses to the newsgroup only.
That means, do not send email directly to me.
Thank you.
Technical Details
Message-ID:
<401eb6e1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<401d06eb$1@newsgroups.borland.com> <pan.2004.02.02.08.34.02.603265@yahoo.de> <401e9d7b@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1089d0,cc9d3c5ba1462852 X-Google-Attributes: gid1089d0,public X-Google-ArrivalTime: 2004-02-02 13:10:29 PST Date: Mon, 02 Feb 2004 15:45:21 -0500 From: Paul Furbacher <pfurbacher@mac.com> User-Agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.jbuilder.java.api Subject: Re: Problems with loading & displaying a picture References: <401d06eb$1@newsgroups.borland.com> <pan.2004.02.02.08.34.02.603265@yahoo.de> <401e9d7b@newsgroups.borland.com> In-Reply-To: <401e9d7b@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 68.39.103.120 Message-ID: <401eb6e1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1075754721 68.39.103.120 (2 Feb 2004 12:45:21 -0800) Lines: 74 Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail