代码之家  ›  专栏  ›  技术社区  ›  Gnark

Eclipse菜单:获取图像的图像描述符?

  •  6
  • Gnark  · 技术社区  · 15 年前

    我不能让这个工作,所以我认为这可能是一个明智的想法张贴在这里。。。

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

    我的问题是 新动物园 图像描述符 .

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

    如果有人能帮我写一段话,那我就有机会了 图像描述符 从一个图像文件这将是太棒了!

    致以最诚挚的问候!


    MenuManager Docu

    2 回复  |  直到 14 年前
        1
  •  13
  •   nanda    15 年前
    Bundle bundle = Platform.getBundle(pluginId);
    URL fullPathString = BundleUtility.find(bundle, "icons/palette_brush.png");
    ImageDescriptor.createFromURL(fullPathString);
    

    pluginId 是放置图标的插件的id。

        2
  •  2
  •   user6669492    9 年前
    Bundle bundle= org.eclipse.core.runtime.Platform.getBundle(pluginId);
    URL fullPathString = bundle.getEntry("icons/palette_brush.png");
    desc= ImageDescriptor.createFromURL(fullPathString);
    desc.createImage();