Solved

ImageIcons???

Posted on 1998-07-28
2
295 Views
Last Modified: 2010-03-30
I have a GUI component which I created, and it has an icon with it.  I want to package the icon with the component so that it is all together.  In my class I have:  new ImageIcon("icons/myIcon.gif")

I also wrote a test program to test the component.
If I run the test program from the same package that the component is in, everything works fine, but if I put the test program outside of the component's package, the icons don't show up.  How can I fix this so that the icons will show up, but I do not want to hard code a path like C:\java\myStuff\gui\icons\myIcon.gif?
For some reason, the only way the icon shows up is if I run
0
Comment
Question by:stepma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 4

Expert Comment

by:evijay
ID: 1228826
The images filenames are taken from the path relative to current execution directory if you dont give absolute path. Rather, put in the properties file for your program, the path from where you want to load the images, read the path and attach image filename and load into image icon.

in fact, ImageIcon source calls Toolkit.getDefaultToolkit.getImage(filename) method to get the image object for the filename. Thus behavior is same as getImage method.

In case of applets, put it in getCodeBase() directory.


0
 
LVL 4

Accepted Solution

by:
evijay earned 50 total points
ID: 1228827
The images filenames are taken from the path relative to current execution directory if you dont give absolute path. Rather, put in the properties file for your program, the path from where you want to load the images, read the path and attach image filename and load into image icon.

in fact, ImageIcon source calls Toolkit.getDefaultToolkit.getImage(filename) method to get the image object for the filename. Thus behavior is same as getImage method.

In case of applets, put it in getCodeBase() directory.


0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question