capint
10/29/2015 - 11:04 AM

Eclipse >> JFace >> Load image from plugin

Eclipse >> JFace >> Load image from plugin

// assumes that you have these two icons in the "icons" folder
private final Image CHECKED = getImage("checked.gif");
private final Image UNCHECKED = getImage("unchecked.gif");

// helper method to load the images
// ensure to dispose the images in your @PreDestroy method
private static Image getImage(String file) {
  // assume that the current class is called View.java
  Bundle bundle = FrameworkUtil.getBundle(View.class);
  // *** We can also get bundle from plugin id: Bundle bundle = Platform.getBundle(PLUGIN_ID);
  URL url = FileLocator.find(bundle, new Path("icons/" + file), null);
  ImageDescriptor image = ImageDescriptor.createFromURL(url);
  return image.createImage();
}