简体   繁体   English

将自定义映像添加到Eclipse SWT

[英]Add custom image to Eclipse SWT

How can I add custom image to Eclipse SWT, I tried use ImageDescriptor. 如何将自定义图像添加到Eclipse SWT,我尝试使用ImageDescriptor。 But I probably do something wrong. 但我可能做错了什么。

private Action stopAction;
stopAction.setText("Stop");
        stopAction.setToolTipText("Stop running");


        stopAction.setImageDescriptor(PlatformUI.getWorkbench().getSharedImages().
                getImageDescriptor(ISharedImages.IMG_OBJS_INFO_TSK));

        ImageDescriptor imgDesc = null;
        try {
            imgDesc = ImageDescriptor.createFromURL(new URL("icons/stop.png"));
        } catch (MalformedURLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        stopAction.setImageDescriptor(imgDesc);

To load the image descriptor from a file in the plugin use: 要从插件中的文件加载图像描述符,请使用:

final URL fullPathString = FileLocator.find(bundle, new Path("icons/stop.png"), null);

ImageDescriptor imgDesc = ImageDescriptor.createFromURL(fullPathString);

where bundle is your plugin bundle, get this from your Activator or: bundle是你的插件包,从你的Activator获取或者:

Bundle bundle = Platform.getBundle("plugin id");

Don't forget to add your icons folder to the build.properties file so that it is included in the built plugin. 不要忘记将您的icons文件夹添加到build.properties文件中,以便它包含在构建的插件中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM