【问题标题】:Eclipse MenuManager: get ImageDescriptor of Image?Eclipse MenuManager:获取图像的 ImageDescriptor?
【发布时间】:2023-03-22 02:11:01
【问题描述】:

我无法让它工作,所以我认为在这里发布可能是一个明智的想法......

我在 SWT 中有一个 上下文菜单(实际上它是一个 Eclipse 插件)。这是一个级联菜单,因此只要您将鼠标悬停在某个条目上,它就会展开...

我的问题是,我想在菜单上附加一个小图标,但我很难做到!

代码: ....

            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);

           ....

我的问题是,new MenuManager 可以使用 2 个参数(无附加图像)或 3 个(附加图像)调用。图像应作为 ImageDescriptor 传递。

问题基本上是:
“如何从图像中获取 Imagedescriptor?”
也许这是一个愚蠢的错误 - 但我无法从图像文件中获取 ImageDescriptor。我有一个可以使用的 *.png 图标,但我很难整合它。

如果有人可以帮忙处理 sn-p,那我可以从图像文件中得到一个 ImageDescriptor,这太棒了!

最好的问候!

MenuManager 文档:
MenuManager Docu

【问题讨论】:

    标签: java image menu swt contextmenu


    【解决方案1】:
    Bundle bundle = Platform.getBundle(pluginId);
    URL fullPathString = BundleUtility.find(bundle, "icons/palette_brush.png");
    ImageDescriptor.createFromURL(fullPathString);
    

    pluginId 是您放置图标的插件的 ID。

    【讨论】:

    • 非常感谢!这就是我最终做到的方式: ImageDescriptor icon = Bundle .getImageDescriptor("icons/palette_brush.png");
    【解决方案2】:
    Bundle bundle= org.eclipse.core.runtime.Platform.getBundle(pluginId);
    URL fullPathString = bundle.getEntry("icons/palette_brush.png");
    desc= ImageDescriptor.createFromURL(fullPathString);
    desc.createImage();
    

    【讨论】:

    • 这实际上可能是一个有用的答案,但如果没有任何上下文或解释就很难说。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-12-11
    • 1970-01-01
    • 2017-05-06
    • 2014-11-01
    • 1970-01-01
    • 2013-06-13
    • 1970-01-01
    相关资源
    最近更新 更多