Hi. I've worked through the three articles "Using the Eclipse GUI
Outside the Eclipse Workbench", but using Eclipse 3.3. For the most
part, everything worked as expected. However, I can't figure out how to
create an executable JAR that allows it to see the graphic icons.
In the article, we are instructed to use the following code to create
the ImageRegistry (where newURL() just puts the URL creation inside a
try/catch block):
public static ImageRegistry getImageRegistry() {
if (image_registry == null) {
image_registry = new ImageRegistry();
image_registry.put("folder",
ImageDescriptor.createFromURL(
newURL("file:icons/folder.gif")));
...
}
return image_registry;
}
This works inside Eclipse with the icons folder just under the Project
(i.g., MyProject/icons/folder.gif). However, when I create a JAR file,
the application can't find the icons.
In searching through posts on this topic, someone suggested using the
following code, with a leading slash:
InputStream in = getClass().getResourceAsStream("/icons/filenew-16.gif");
if (in != null) {
try {
ImageData id = new ImageData(in);
...
} finally {
in.close();
}
}
In order for this to work both for development and runtime, they also
said that this would require moving the icons directory underneath the
src directory.
I tried moving the icons directory underneath my src/com/mark/gui folder
(my package name is "com.mark.gui") and modifying the ImageRegistry code
to use the following:
image_registry.put("folder",
ImageDescriptor.createFromURL(
newURL("file:/src/com/mark/gui/icons/folder.gif")));