Sunday, July 25, 2010

Locate Images in and out From Your Eclipse RCP application

Loading images and other resources are a little different in Eclipse RCP than the normal Java applications. In this post, I'm going to list all the possible ways to locate images in and out of your Eclipse RCP applications.

To simplify the example code, I only show you how to get ImageDescriptor. After that, you can use createImage() to crate Image object from

1. Icons Folder Inside RCP project



Activator.getImageDescriptor("icons/tray.png");

2. from class path

If images are saved in the same place as your class:


ImageDescriptor.createFromFile(
    BookCoverView.class, "cover.jpg");


3. from external disk or Internet

This is helpful when you ask user to specify a image from their disk.

ImageDescriptor.createFromURL(
new URL("file:d://icons/info2.gif"));

4. reuse Eclipse's icons


Many common images (undo, redo, file, folder, cut, copy) are available thru the org.eclipse.ui.ISharedImages interface. You can get them with IWorkbench:



PlatformUI.getWorkbench().getSharedImages()
.getImage(ISharedImages.IMG_OBJ_FOLDER);

source: http://blog.cypal-solutions.com/2008/02/eclipse-icons.html


5. Access icons from other plugin


access the icons from other plugins without bundling them in your plugin:

AbstractUIPlugin.imageDescriptorFromPlugin(
"org.eclipse.ui", "$nl$/icons/import_wiz.gif");


source: http://blog.cypal-solutions.com/2008/02/eclipse-icons-follow-up-post.html







1 comments:

rub.l said...

Hi, I have command (RCP app) which use image from other plugin(../otherPlugin/im.gif). When I run it in workspace everything is OK, but after exporting to exe images disapear. Any suggestion ?
Thanks, Petr