Gnark Gnark - 6 months ago 45
Java Question

Eclipse MenuManager: get ImageDescriptor of Image?

I cannot get this to work so I thought it might be a wise idea posting over here...
I have a context menu in SWT (actually its an Eclipse plugin). It's a cascaded menu, so it expands as soon as you hover over a certain entry...

My problem is, that I want to attach a small icon to the menu but I struggle with that!


manager.add(new Separator());

// icon for the "change color" menu
ImageDescriptor icon = ImageDescriptor.createFromFile(null,

// submenu
MenuManager colorMenu = new MenuManager("Menu", icon, null);

// Actions

// add the action to the submenu


My problem is, that the new MenuManager can either be called with 2 Arguments (no attached image) or 3 (with attached image). The image should be passed along as ImageDescriptor.
The question basically is:

"How can I get an Imagedescriptor off an image?"

Maybe it's an stupid mistake - but I cannot get an ImageDescriptor from an image file. I have an *.png icon ready to use, but I struggle incorporating this.
If anyone could help out with a snippet, that would get me an ImageDescriptor from an image file this would be soo awesome!

Best regards!

MenuManager Documentation:

MenuManager Docu

Bundle bundle = Platform.getBundle(pluginId);
URL fullPathString = BundleUtility.find(bundle, "icons/palette_brush.png");

pluginId is the id of the plugin where you put your icon.