将自定义图像添加到RCP应用程序中的Action

时间:2015-10-19 07:56:50

标签: java eclipse-plugin icons swt eclipse-rcp

我使用this教程在Eclipse应用程序中创建了一个自定义视图。我还添加了一些自定义Action,我想为它们分配自定义图标。我尝试使用setImageDescriptor()(正如您在下面的代码中看到的那样)但不幸的是我只看到了我的栏中的文字,但没有图标。

private void createActions() {
    Action myAction = new Action("My Action") {
        public void run() {
            // do something
        }
    };
    myAction.setImageDescriptor(Activator.getImageDescriptor("icons/my_action.gif"));
}

Acrivator类看起来像这样:

public class Activator extends AbstractUIPlugin {

    // The plug-in ID
    public static final String PLUGIN_ID = "my.product.plugin"; //$NON-NLS-1$

    // standard stuff...

    public static ImageDescriptor getImageDescriptor(String path) {
        return imageDescriptorFromPlugin(PLUGIN_ID, path);
    }
}

有人可以帮忙吗?

解决方案:插件ID不正确,但它是自动生成的。更改后,图标设置正确。

0 个答案:

没有答案