SWT中在treeview中显示图片
package com.repositoryclient.treeview; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.viewers.ILabelProvider; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.tmatesoft.svn.core.SVNNodeKind; public class TreeLabelProvider extends LabelProvider implements ILabelProvider{ public Image iconFolder = null; public Image iconFile = null; public TreeLabelProvider() { this.iconFolder = getImageDescriptor("icons/folder.png").createImage(); //folder.png是本项目中icons文件夹中的图片 this.iconFile = getImageDescriptor("icons/file.png").createImage(); } public ImageDescriptor getImageDescriptor(String path) { return AbstractUIPlugin.imageDescriptorFromPlugin("RepositoryClient", path); //这里这个函数的第一个参数是本插件的ID,第二个参数是本插件中图片的的相对路径 } public String getText(Object element){ FileNode node=(FileNode)element; return node.getFileName(); } public Image getImage(Object element){ FileNode node=(FileNode)element; if (node.getKind() == SVNNodeKind.DIR) { return iconFolder; } if (node.getKind() == SVNNodeKind.FILE) { return iconFile; } return null; } }
相关推荐
wikiwater 2020-10-27
IdeaElements 2020-08-19
Sophiego 2020-08-16
Kakoola 2020-08-01
Kakoola 2020-07-29
ELEMENTS爱乐冬雨 2020-07-18
ELEMENTS爱乐小超 2020-07-04
ELEMENTS爱乐小超 2020-07-04
Kakoola 2020-06-28
Feastaw 2020-06-18
Wmeng0 2020-06-14
ELEMENTS爱乐冬雨 2020-06-14
云之高水之远 2020-06-14
哈喽elements 2020-06-14
Feastaw 2020-06-11