扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
在本页阅读全文(共4页)
??????? /*
???????? * 生成城市里的人
???????? */
??????? {
??????????? List list = new ArrayList();
??????????? list.add(new People("陈刚"));
??????????? list.add(new People("陈知行"));
??????????? list.add(new People("韩立新"));
??????????? glCity.setPeoples(list);
??????? }
??????? {
??????????? List list = new ArrayList();
??????????? list.add(new People("桃子"));
??????????? list.add(new People("林雅仕"));
??????????? list.add(new People("陈常恩"));
??????????? nnCity.setPeoples(list);
??????? }
??????? return countryArray;
??? }
}
?
?
/*
?* @author 陈刚 ,2004-8-21 0:54:20
?* Email: glchengang@yeah.net
?* Blog : glchengang.yeah.net
?*/
package book.c3.e2;
import org.eclipse.jface.viewers.ITreeContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreeViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import java.util.List;
public class S3_1 {
??? public static void main(String[] args) {
??????? S3_1 window = new S3_1();
??????? window.open();
??? }
??? public void open() {
??????? final Display display = new Display();
??????? final Shell shell = new Shell();
??????? shell.setLayout(new FillLayout());
??????? ui(shell);
??????? shell.open();
??????? while (!shell.isDisposed()) {
??????????? if (!display.readAndDispatch())
??????????????? display.sleep();
??????? }
??? }
??? private void ui(Shell shell) {
??????? Composite c = new Composite(shell, SWT.NONE);
??????? c.setLayout(new FillLayout());
??????? TreeViewer tv = new TreeViewer(c, SWT.BORDER);
??????? tv.setContentProvider(new MyContentProvider());
??????? tv.setLabelProvider(new MyLableProvider());
??????? tv.setInput(new TvInputFactory().build());//设置输入对象的方法与前面相同
??? }
??? /**
???? * 内容提供器。由它决定那些对象应该输出在TreeViewer里显示
???? */
??? private static final class MyContentProvider implements ITreeContentProvider {
??????? /**
???????? * 由这个方法决定树的顶级显示那些对象。在此方法里生成了三个Country对象
???????? * @param inputElement? 用tv.setInput()方法输入的那个对象,在这里没有使用这个对象
???????? */
??????? public Object[] getElements(Object inputElement) {
??????????? if (inputElement instanceof Country[])
??????????????? return (Country[]) inputElement;
??????????? return new Object[0]; //生成一个空数组
??????? }
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者