Swt/Jface listviewer的实现
来源:互联网 发布:unity3d 面部表情 编辑:程序博客网 时间:2024/05/16 17:55
前边将过了TableViewer和TreeViewer再来看ListViewer就简单了,操作步骤一样,但更简单。这里只给出使用的代码一、代码,这个实现不同于前边是分开实现(都是public 的类),这里给出的是内部类的实现方式。
import java.util.ArrayList;import java.util.List;import org.eclipse.jface.viewers.IStructuredContentProvider;import org.eclipse.jface.viewers.LabelProvider;import org.eclipse.jface.viewers.ListViewer;import org.eclipse.jface.viewers.Viewer;import org.eclipse.swt.SWT;import org.eclipse.swt.graphics.Image;import org.eclipse.swt.layout.FillLayout;import org.eclipse.swt.widgets.Display;import org.eclipse.swt.widgets.Shell;public class TestListViewer { static class ListLabelProvider extends LabelProvider { public String getText(Object element) { Country country = (Country)element; return country.getName(); } public Image getImage(Object element) { return null; } } static class ContentProvider implements IStructuredContentProvider { public Object[] getElements(Object inputElement) { if(inputElement instanceof List){ List list = (List)inputElement; return list.toArray(); } return new Object[0]; } public void dispose() { } public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { } } static class Country { private String name; public Country(){ } public Country(String name){ this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } public static List getCountryList(){ List list = new ArrayList(); list.add(new Country("中国")); list.add(new Country("美国")); list.add(new Country("日本")); return list; } } private static org.eclipse.swt.widgets.List list; /** *//** * Launch the application * @param args */ public static void main(String[] args) { final Display display = Display.getDefault(); final Shell shell = new Shell(); shell.setSize(500, 375); shell.setText("SWT Application"); // shell.open(); final ListViewer listViewer = new ListViewer(shell, SWT.BORDER); listViewer.setLabelProvider(new ListLabelProvider()); listViewer.setContentProvider(new ContentProvider()); listViewer.setInput(new Object()); list = listViewer.getList(); list.setBounds(122, 63, 100, 100); listViewer.setContentProvider(new ContentProvider()); listViewer.setLabelProvider(new ListLabelProvider()); listViewer.setInput(Country.getCountryList()); //可以直接添加 listViewer.add(new Country("英国")); shell.setLayout(new FillLayout()); shell.layout(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } }}
二、注意代码的注释部分,可以直接添加和移除。
- Swt/Jface listviewer的实现
- Swt/Jface listviewer的实现
- Swt/Jface listviewer的实现
- SWT/JFace的对话框
- 实现SWT(JFace)里的表格隔行换色功能
- SWT/Jface TreeViewer 上移和下移按钮的简单实现
- swt/jface的事件模型
- SWT/JFACE学习的积累
- Swt/Jface treeViewer的使用
- Swt/Jface treeViewer的使用
- SWT-JFace开发的利器
- Swt/Jface treeViewer的使用
- SWT/Jface 窗口的样式
- Swt/Jface treeViewer的使用
- NFace TreeViewer 和ListViewer(JFace Viewer在.Net中的简单实现)
- SWT/JFACE
- JFace/SWT
- SWT Jface
- Swt/Jface tableViewer入门教程2
- Symbian OS中的RArray类的排序功能
- Swt/Jface tableviewer入门教程3
- Swt/Jface tableviewer入门教程4
- 全面剖析XMLHttpRequest对象
- Swt/Jface listviewer的实现
- Swt/Jface treeViewer的使用
- 批量数据库拷贝
- 在C#中调用exe文件。
- 为 Eclipse 构建片段扩展
- 电脑桌面图标底色去除
- 连载:大学生求职七大昏招(十)抱怨(1)
- 电脑桌面图标底色去除
- 名字中,欠什么就补什么