Article View: borland.public.jbuilder.java.swing
Article #1322Re: How to use images from up directories?
From: Kevin Dean
Date: Wed, 07 Jan 2004 14:48
Date: Wed, 07 Jan 2004 14:48
71 lines
3140 bytes
3140 bytes
I ran into similar problems some time ago. The issue is that Java doesn't
support ".." directories when locating resources.
What you need to do is find some class in a parent directory (or create a
dummy one) and use it to load the resources. In your case, create a class
called com.mycompany.ImageLoader and use it as follows:
jButton1.setIcon(new
ImageIcon(ImageLoader.class.getResource("myimages/myPicture.PNG")));
It does mean modifying JBuilder's generated code, but once you've done so
once JBuilder should leave it alone.
--
Check out our latest white papers at
http://www.datadevelopment.com/papers/index.html
BladeNET Scores With Borland Enterprise Tools
Team Development with JBuilder and Borland Enterprise Server
Dolphin Data Development Ltd.
http://www.datadevelopment.com/
"Rocket" <rocket@via.com.br> wrote in message
news:3ffb2887$3@newsgroups.borland.com...
> Hi, sorry my bad english,
>
> I have problems with images and directories in JBuilder.
>
> If I have an image in directory below from current directory, Jbuilder
> create an code like this for an Icon:
>
> jButton1.setIcon(new
> ImageIcon(Frame1.class.getResource("img/myPicture.PNG")));
>
> OK, it�s works... :-|
>
> But, if I have the images in above directories, JBuilder creates a code
like
> this:
>
> jButton.setIcon(new ImageIcon(new
>
java.net.URL("file:///C:/projects/mysystem/src/com/mycompany/myimages/myPict
> ure.PNG")));
>
> In other words, it put full path for the image.
>
> My system like is:
>
> package com.mycompany.mysystem.ihc
> public class MyFrame extends JFrame {
> ...
> }
>
> ...And the images are in package com.mycompany.myimages. (2 up�s
> directories)
>
> Using Design, the JBuilder creates an code like this:
> ...
> jLabel1.setIcon(new ImageIcon(new
>
java.net.URL("file:///C:/projects/mysystem/src/com/mycompany/myimages/myPict
> ure.PNG")));
> ...
>
> Obviously, this code will not function at client...
>
> How I use the Design (and configurate paths...) to create a correct code?
>
>
Technical Details
Message-ID:
<3ffc1c93$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<3ffb2887$3@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 111d45,ed0e58961208387c X-Google-Attributes: gid111d45,public X-Google-ArrivalTime: 2004-01-07 07:09:53 PST From: "Kevin Dean" <NkOdSePaAnM@datadevelopment.com> Newsgroups: borland.public.jbuilder.java.swing References: <3ffb2887$3@newsgroups.borland.com> Subject: Re: How to use images from up directories? Date: Wed, 7 Jan 2004 09:48:23 -0500 Lines: 73 Organization: Dolphin Data Development Ltd. 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.57.150.243 Message-ID: <3ffc1c93$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1073486995 24.57.150.243 (7 Jan 2004 06:49:55 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!newsfeed2.dallas1.level3.net!news.level3.com!news-out.visi.com!petbe.visi.com!news.tele.dk!news.tele.dk!small.news.tele.dk!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail