如何在 SWT 中将背景图像设置为 shell 或合成
How to set background image to shell or composite in 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类型。
提前致谢。
您在 Eclipse 插件中使用 FileLocator
在插件中查找资源。
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
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类型。
提前致谢。
您在 Eclipse 插件中使用 FileLocator
在插件中查找资源。
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