Java元素图标SWT ECLIPSE [英] Java element icons SWT ECLIPSE
问题描述
如何在SWT的Tree控件中添加java元素图标(例如,包资源管理器中的类,方法,包等)?
How to add the java element icons (e.g. class, methods, package, etc as that in the package explorer) in SWT's Tree control?
例如,我有以下树结构:
somePackage
e.g, I have the following tree structure: somePackage
--> somePackage
|
|--> someClass
|
|--> someMethod
这里 - >
表示折叠图标。我想保持这个完整,但另外我想要有相应的java元素的适当的图标(因为它在包资源管理器中可见)。我使用SWT树构建树视图。以下是构造它的代码:
Here -->
represents the folding icon. I want to keep this intact but additionally I want to have the appropriate icon for respective java element (as it is visible in the package explorer). I am using SWT Tree to built the tree view. following is the code to construct it:
final Tree tree = new Tree (composite, SWT.BORDER);
for (int i=0; i<4; i++) {
// Package
TreeItem iItem = new TreeItem (tree, 0);
iItem.setText ("TreeItem (0) -" + i);
for (int j=0; j<4; j++) {
// Class
TreeItem jItem = new TreeItem (iItem, 0);
jItem.setText ("TreeItem (1) -" + j);
for (int k=0; k<4; k++) {
// Method or Fields
TreeItem kItem = new TreeItem (jItem, 0);
kItem.setText ("TreeItem (2) -" + k);
}
}
}
tree.setBounds(25, 50, 580, 200);
推荐答案
您可以添加依赖关系 org.eclipse.jdt.ui
到您的项目,以访问JDT项目的共享映像。以下代码适用于Eclipse 3.x。对于简单的SWT应用程序(没有Eclipse插件),您需要添加一堆eclipse插件(包括org.eclipse.jdt.ui)以在项目中获取此功能。
You can add the dependency org.eclipse.jdt.ui
to your project to get access to the shared images of the JDT project. The following code works for Eclipse 3.x. For plain SWT applications (no Eclipse plugin) you need to add a bunch of eclipse plugins (including org.eclipse.jdt.ui) to get this functionality in your project.
import org.eclipse.jdt.ui.ISharedImages;
import org.eclipse.jdt.ui.JavaUI;
...
ISharedImages images = (ISharedImages) JavaUI.getSharedImages();
Image image = images.getImage(ISharedImages.IMG_OBJS_CLASS); // class file icon
编辑:
如果你不想要包括所有的库只是因为你想要使用一些eclipse图像:我在网页上找到了所有eclipse共享映像的列表。 (基于eclipse 3.4)
If you don't want to include all the libraries only because you want to use a a few eclipse images: I found a list of all eclipse shared images in the web. (based on eclipse 3.4)
资料来源:
界面org.eclipse。 jdt.ui.ISharedImages
这篇关于Java元素图标SWT ECLIPSE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!