eclipse-plugin - 如何在 SWT 中将背景图像设置为外壳或合成
问题描述
public class createShell{
System.out.println("Inside shell create");
display = new Display();
shell = new Shell(display);
shell.setSize(990, 590);
shell.setLayout(new GridLayout());
Composite comp = new Composite(shell, SWT.NO_FOCUS);
comp.setBounds(10, 10, 720, 400);
}
我有这样的现有代码。需要给shell设置一个背景图片。如何给出图像的相对路径。插件(com.vcc.rac.ks5lmpp)的文件夹结构与图像相同。path代码文件在包里面的src文件夹(plugins\com.rac.ks5lmpp\src\com\kjj\rac\ks5lmpp\stylesheets\dialogs\createShell.java) 有一个图片文件夹(plugins\com.rac.ks5lmpp \src\com\kjj\rac\ks5lmpp\stylesheets\dialogs\images),其中有我想作为背景传递的图像。图像大小为 676X324 的 PNG 类型。
提前致谢。
解决方案
您FileLocator
在 Eclipse 插件中使用以在插件中查找资源。
Bundle bundle = FrameworkUtil.getBundle(getClass()); // Or some other way to find the current bundle
URL url = FileLocator.find(bundle, new Path("path within the plugin"));
ImageDescriptor desc = ImageDescriptor.createFromURL(url);
Image image = desc.createImage();
shell.setBackgroundImage(image);
注意:您应该安排在 shell 关闭时处理图像。
确保build.properties
插件的 包含图像。
FileLocator
是org.eclipse.core.runtime.FileLocator
。
Path
是org.eclipse.core.runtime.Path
(不是 java.nio.file 路径)
ImageDescriptor
是org.eclipse.jface.resource.ImageDescriptor
推荐阅读
- android - 如何在运行 Android CTS 测试时禁用日志
- android - 在数据库andoid studio中插入数据的问题
- javascript - 无法根据 JSON 输出设置变量
- python - 我怎样才能阻止函数在它打算之前写入文本文件?
- c# - C# 控制台:System.Net.WebException:底层连接已关闭:
- uwp - 如何在打印机列表中列出我自己的 UWP 应用程序,例如 Microsoft Print to PDF 或 OneNote for windows 10?
- azure-cosmosdb - Cosmos SQL 数据库创建项
- amazon-web-services - 我没有使用的服务的 AWS 账单
- windows-server-2016 - 无法从 Windows Server 2016 Datacenter 卸载 IIS 10
- python - 在内存中处理非常大的字符串