将图像导入 Eclipse 插件

uma*_*uma 1 swt eclipse-plugin

我已经使用 Java SWT 开发了一个 Eclipse 插件。我的插件很少有向导页面。现在,我需要在向导页面的标题部分添加一个图像/徽标。任何人都可以就如何使用 SWT 做同样的事情提出建议。

gre*_*449 5

插件中的图像通常放置在imagesicons文件夹中 - 不要忘记将此文件夹添加到 中,build.properties以便将其包含在构建的插件中。

您可以使用以下方法从文件夹加载图像:

final URL fullPathString = FileLocator.find(bundle, new Path(path), null);

ImageDescriptor imageDesc = ImageDescriptor.createFromURL(fullPathString);

Image image = imageDesc.createImage();
Run Code Online (Sandbox Code Playgroud)

bundle是你的插件Bundle,你可以从你的激活器(如果你有)或使用:

Bundle bundle = Platform.getBundle("plugin id");
Run Code Online (Sandbox Code Playgroud)

或者

Bundle bundle = FrameworkUtil.getBundle(getClass());
Run Code Online (Sandbox Code Playgroud)

path 是相对于插件的图像路径 - 所以像 images/xxx.gif

如果你创建了一个Image你必须在完成后处理它(ImageDescriptor不需要处理)。

您可以使用org.eclipse.jface.resource.ImageRegistry来管理图像和图像描述符。

更新:

一旦你有了一个,ImageDescriptor你就可以通过调用将它设置为向导页面上的标题图像WizardPage.setImageDescriptor(descriptor)