Eclipse插件设置自定义对话框的图像图标

时间:2016-08-30 08:18:15

标签: java eclipse plugins

我制作了一个自定义Eclipse插件,它使用并显示多个对话框,我想知道是否可以使用我在插件的awk '/^\S/ {core=0} /^_core/ {core=1} !core {print}' views.view.who_s_online.yml|head uuid: 50715f68-3b13-4a15-8455-853110fd1d8b langcode: en status: true dependencies: module: - user id: who_s_online label: 'Who''s online block' module: user description: 'Shows the user names of the most recently active users, and the total number of active users.' 文件夹中使用的图像设置左上角图标。我想获取该图标并设置它而不是Eclipse使用的默认图标。 我正在覆盖icons方法来更改对话框标题,我还想更改图标。

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); } 并将图像放在同一个包中,仍然无法找到我给出的位置(FileNotFoundException),而getClass().getResource("best.gif")构造函数也不接受网址对象。

Image

有没有办法使用我在eclipse插件中已有的图标? 主要问题是从插件的@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); } 文件夹中获取图标并将其设为icons对象。
谢谢。

2 个答案:

答案 0 :(得分:2)

您可以在插件activator class中注册图标,如下所示:

@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);

(请注意,我在图像注册表中使用图像路径作为键,您不必像这样做,但只需使用相同的静态String就可以使一切变得简单。)< / p>

答案 1 :(得分:2)

对于Eclipse插件,您可以使用FileLocator类在插件中查找资源。

对于图像使用类似:

String path = "icons/best.gif";

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

ImageDescriptor desc = ImageDescriptor.createFromURL(url);

Image image = desc.createImage();

注意:您必须安排在不再需要时处理图像。

如果您的激活器延长AbstractUIPlugin,您也可以使用其中的ImageRegistry。注册表将处理处置。

确保icons目录列在build.properties文件中。导出插件时,如果缺少此项将导致问题。

相关问题