我制作了一个使用并显示多个对话框的自定义Eclipse插件,我想知道是否可以将左上角的图标图像设置为该插件icons
文件夹中使用的图标图像。我想要获取并设置该图标,而不是Eclipse使用的默认图标。我正在覆盖configureShell()
更改对话框标题的方法,并且我也想更改图标。
@Override
protected void configureShell(Shell parent){
super.configureShell(parent);
parent.setText("Choose variant...");
Image icon = new Image(parent.getDisplay(), "icons/best.gif"); - this method does not work as it cannot find the file
parent.setImage(icon);
}
我还尝试过使用getClass().getResource("best.gif")
和在同一包中包含图像,但仍然找不到我给的位置(FileNotFoundException),而且Image
构造函数也不接受URL对象。
@Override
protected void configureShell(Shell parent){
super.configureShell(parent);
parent.setText("Choose variant...");
Image icon = new Image(parent.getDisplay(), getClass().getResource("icons/best.gif"));
parent.setImage(icon);
}
有没有办法使用我在eclipse插件中已经拥有的图标?主要问题是从icons
插件的文件夹中获取图标并将其作为Image
对象。
谢谢你。
您可以像这样在插件激活器类中注册图标:
@Override
protected void initializeImageRegistry(final ImageRegistry reg) {
reg.put(IMAGE_PATH, imageDescriptorFromPlugin(PLUGIN_ID, IMAGE_PATH));
}
图像路径是相对于您的插件的,例如icons/icon.png
。
您也可以通过激活器类访问这些图像:
final Image image = MyActivatorClass.getDefault().getImageRegistry().get(IMAGE_PATH);
myShell.setImage(image);
(请注意,我在图像注册表中使用了图像路径作为键,您不必这样做,但是只需使用相同的static,就可以使所有操作稍微复杂一些String
。)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句