我已经使用Java SWT开发了eclipse插件。我的插件只有几个向导页面。现在,我需要在向导页面的标题部分添加图像/徽标。任何人都可以提出有关如何使用SWT进行操作的建议。
插件中的图像通常放置在images
或icons
文件夹中-不要忘记将此文件夹添加到build.properties
中,以便将其包含在内置插件中。
您使用以下方法从文件夹中加载图像:
final URL fullPathString = FileLocator.find(bundle, new Path(path), null);
ImageDescriptor imageDesc = ImageDescriptor.createFromURL(fullPathString);
Image image = imageDesc.createImage();
[bundle
是您的插件Bundle
,您可以从激活器(如果有)获得此插件,或者使用:]]
Bundle bundle = Platform.getBundle("plugin id");
或
Bundle bundle = FrameworkUtil.getBundle(getClass());
[
path
是相对于插件的图像路径-类似于images/xxx.gif
如果创建Image
,则必须在完成后将其处置(无需处置ImageDescriptor
)。
您可以使用org.eclipse.jface.resource.ImageRegistry
管理图像和图像描述符。
更新:
一旦有了ImageDescriptor
,就可以通过调用WizardPage.setImageDescriptor(descriptor)
将其设置为向导页面上的标题图像。