Java Eclipse菜单管理器:获取图像的ImageDescriptor?
我不能让它工作,所以我认为在这里张贴可能是一个明智的想法… 我在SWT中有一个上下文菜单(实际上是一个Eclipse插件)。这是一个层叠菜单,因此当您将鼠标悬停在某个条目上时,它会立即展开… 我的问题是,我想在菜单上附加一个小图标,但我很难做到这一点 代码:Java Eclipse菜单管理器:获取图像的ImageDescriptor?,java,image,menu,swt,contextmenu,Java,Image,Menu,Swt,Contextmenu,我不能让它工作,所以我认为在这里张贴可能是一个明智的想法… 我在SWT中有一个上下文菜单(实际上是一个Eclipse插件)。这是一个层叠菜单,因此当您将鼠标悬停在某个条目上时,它会立即展开… 我的问题是,我想在菜单上附加一个小图标,但我很难做到这一点 代码: manager.add(new Separator()); // icon for the "change color" menu ImageDescriptor
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);
....
我的问题是,可以使用2个参数(无附加图像)或3个参数(附加图像)调用新的菜单管理器。图像应作为ImageDescriptor传递
问题基本上是:“如何从图像中获取图像描述符?”
也许这是一个愚蠢的错误——但我无法从图像文件中获取ImageDescriptor。我有一个*.png图标可以使用,但我很难将其合并。 如果有人能帮我写一个片段,那我就可以从一个图像文件中得到一个ImageDescriptor了,这太棒了! 致以最良好的祝愿 菜单管理器文档:
pluginId
是您放置图标的插件id。非常感谢!这就是我最终的做法:ImageDescriptor icon=Bundle.getImageDescriptor(“icons/palete_brush.png”);这实际上可能是一个有用的答案,但如果没有任何上下文或解释,很难说出。
Bundle bundle= org.eclipse.core.runtime.Platform.getBundle(pluginId);
URL fullPathString = bundle.getEntry("icons/palette_brush.png");
desc= ImageDescriptor.createFromURL(fullPathString);
desc.createImage();
Bundle bundle= org.eclipse.core.runtime.Platform.getBundle(pluginId);
URL fullPathString = bundle.getEntry("icons/palette_brush.png");
desc= ImageDescriptor.createFromURL(fullPathString);
desc.createImage();