Reputation: 3539
How can I add custom image to Eclipse SWT, I tried use ImageDescriptor. But I probably do something wrong.
private Action stopAction;
stopAction.setText("Stop");
stopAction.setToolTipText("Stop running");
stopAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));
ImageDescriptor imgDesc = null;
try {
imgDesc = ImageDescriptor.createFromURL(new URL("icons/stop.png"));
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
stopAction.setImageDescriptor(imgDesc);
Upvotes: 1
Views: 475
Reputation: 111142
To load the image descriptor from a file in the plugin use:
final URL fullPathString = FileLocator.find(bundle, new Path("icons/stop.png"), null);
ImageDescriptor imgDesc = ImageDescriptor.createFromURL(fullPathString);
where bundle
is your plugin bundle, get this from your Activator or:
Bundle bundle = Platform.getBundle("plugin id");
Don't forget to add your icons
folder to the build.properties
file so that it is included in the built plugin.
Upvotes: 3