I have a RCP application, in which I have added some images as icons. The below method is the method for adding icons on the buttons:
public static void setIconForButton(Button button, Display d, Bundle bundle, String path) {
InputStream is = null;
try {
is = FileLocator.openStream(bundle, new Path(path), false);
Image image = new Image(d, is);
button.setImage(image);
} catch (IOException e1) {
e1.printStackTrace();
} finally {
try {
if (is != null) {
is.close();
}
} catch (Exception e1) {
e1.printStackTrace();
}
}
}
where,
Button button
--> the button on which I need to add icons,
Display d
--> current display,
Bundle bundle
--> FrameworkUtil.getBundle(getClass());,
String path
--> path of the icon.(for example - /icons/expandall.gif)
All the images are stored in icons
folder which is directly under the root project folder.
Note: I have no other references anywhere else in the whole project of the icons folder.