Eclipse MenuManager: get ImageDescriptor of Image?
Asked Answered
I

2

7

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!

Code: ....

            manager.add(new Separator());

            // icon for the "change color" menu
            ImageDescriptor icon = ImageDescriptor.createFromFile(null,
                "icons/palette_brush.png");

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

            // Actions
            colorMenu.add(someAction);

            // add the action to the submenu
            manager.add(colorMenu);

           ....

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

Indiaindiaman answered 21/9, 2010 at 10:27 Comment(0)
P
14
Bundle bundle = Platform.getBundle(pluginId);
URL fullPathString = BundleUtility.find(bundle, "icons/palette_brush.png");
ImageDescriptor.createFromURL(fullPathString);

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

Ptolemaic answered 21/9, 2010 at 11:13 Comment(1)
thanks a lot! This is how i finally did it: ImageDescriptor icon = Bundle .getImageDescriptor("icons/palette_brush.png");Indiaindiaman
P
3
Bundle bundle= org.eclipse.core.runtime.Platform.getBundle(pluginId);
URL fullPathString = bundle.getEntry("icons/palette_brush.png");
desc= ImageDescriptor.createFromURL(fullPathString);
desc.createImage();
Phytography answered 2/8, 2016 at 20:17 Comment(1)
This may actually be a helpful answer but it's hard to tell without any context or explanation.Lungwort

© 2022 - 2024 — McMap. All rights reserved.