gpt4 book ai didi

java - Eclipse 插件为自定义对话框设置图像图标

转载 作者:行者123 更新时间:2023-11-29 08:42:07 24 4
gpt4 key购买 nike

我制作了一个使用和显示多个对话框的自定义 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 对象。
谢谢。

最佳答案

您可以在您的插件中注册图标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 可以使一切变得不那么复杂.)

关于java - Eclipse 插件为自定义对话框设置图像图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39222232/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com