Thread View: borland.public.jbuilder.java.swing
2 messages
2 total messages
Started by GEORGE
Wed, 17 Aug 2005 23:21
using icons
Author: GEORGE
Date: Wed, 17 Aug 2005 23:21
Date: Wed, 17 Aug 2005 23:21
10 lines
1305 bytes
1305 bytes
I load icons with ImageIcon("icons/filename.png"). This is fine for my app
because I always run from within JBuilder so I just have to place the icons
directory under the project directory. I think this will most likely not
work if the app was being run from a jar file.
What is the most general way to solve this issue? i.e how to load icons in
a way that is independent of the way the program is run?
TIA
George
Re: using icons
Author: Lori M Olson [TeamB]
Date: Fri, 19 Aug 2005 15:16
Date: Fri, 19 Aug 2005 15:16
51 lines
2849 bytes
2849 bytes
GEORGE wrote:
> I load icons with ImageIcon("icons/filename.png"). This is fine for my app
> because I always run from within JBuilder so I just have to place the icons
> directory under the project directory. I think this will most likely not
> work if the app was being run from a jar file.
>
> What is the most general way to solve this issue? i.e how to load icons in
> a way that is independent of the way the program is run?
>
> TIA
> George
>
>
There are many different ways of dealing with these issues. It would
take hours to run thru all of them. I'll just try to explain the
problem, and then my preferred solution, but keep in mind that there are
other ways...
The problem you have here is that ImageIcon("icons/filename.png") is
using the form of ImageIcon that is going directly to the file system,
and it is using a relative path. So, this works for JBuilder, because
it always runs from the project directory and finds your files w.r.t
that directory.
A more robust way, is to place the images in your *classpath* (add the
files to your project, and make sure JBuilder is configured to copy
those types of files to the classpath), and then access them as
"resources" from the classpath. The Swing Tutorial actually illustrates
this way of loading images:
http://java.sun.com/docs/books/tutorial/uiswing/misc/icon.html
--
Regards,
Lori Olson [TeamB]
------------
Save yourself, and everyone else, some time and search the
newsgroups and the FAQ-O-Matic before posting your next
question.
Google Advanced Newsgroup Search
http://www.google.ca/advanced_group_search
Other Newsgroup Searches:
http://www.borland.com/newsgroups/ngsearch.html
Joi Ellis's FAQ-O-Matic:
http://www.visi.com/~gyles19/fom-serve/cache/1.html
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads