import java.awt.Image;import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;public class TestMain
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("List Viewer Example");
shell.setBounds(100, 100, 300, 200);
shell.setLayout(new FillLayout()); final ListViewer lv = new ListViewer(shell, SWT.SINGLE);
lv.setContentProvider(new ArrayContentProvider());
lv.setLabelProvider(new PersonListLabelProvider());
lv.setInput(Person.example()); shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose(); }}class Person
{
public String firstName = "John";
public String lastName = "Doe";
public int age = 37;
public Person[] children = new Person[0];
public Person parent = null; public Person(String firstName, String lastName, int age)
{
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
} public Person(String firstName, String lastName, int age, Person[] children)
{
this(firstName, lastName, age);
this.children = children;
for (int i = 0; i < children.length; i++)
{
children[i].parent = this;
}
} public static Person[] example()
{
return new Person[] {
new Person("Dan", "Rubel", 41, new Person[] {
new Person("Beth", "Rubel", 11),
new Person("David", "Rubel", 6) }),
new Person("Eric", "Clayberg", 42, new Person[] {
new Person("Lauren", "Clayberg", 9),
new Person("Lee", "Clayberg", 7) }),
new Person("Mike", "Taylor", 55) };
} public String toString()
{
return firstName + " " + lastName;
}
}class PersonListLabelProvider extends LabelProvider
{
public String getText(Object element)
{
Person person = (Person) element;
return person.firstName + " " + person.lastName;
}
}
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;public class TestMain
{
public static void main(String[] args)
{
// TODO Auto-generated method stub
Display display = new Display();
Shell shell = new Shell(display);
shell.setText("List Viewer Example");
shell.setBounds(100, 100, 300, 200);
shell.setLayout(new FillLayout()); final ListViewer lv = new ListViewer(shell, SWT.SINGLE);
lv.setContentProvider(new ArrayContentProvider());
lv.setLabelProvider(new PersonListLabelProvider());
lv.setInput(Person.example()); shell.open();
while (!shell.isDisposed())
{
if (!display.readAndDispatch())
display.sleep();
}
display.dispose(); }}class Person
{
public String firstName = "John";
public String lastName = "Doe";
public int age = 37;
public Person[] children = new Person[0];
public Person parent = null; public Person(String firstName, String lastName, int age)
{
this.firstName = firstName;
this.lastName = lastName;
this.age = age;
} public Person(String firstName, String lastName, int age, Person[] children)
{
this(firstName, lastName, age);
this.children = children;
for (int i = 0; i < children.length; i++)
{
children[i].parent = this;
}
} public static Person[] example()
{
return new Person[] {
new Person("Dan", "Rubel", 41, new Person[] {
new Person("Beth", "Rubel", 11),
new Person("David", "Rubel", 6) }),
new Person("Eric", "Clayberg", 42, new Person[] {
new Person("Lauren", "Clayberg", 9),
new Person("Lee", "Clayberg", 7) }),
new Person("Mike", "Taylor", 55) };
} public String toString()
{
return firstName + " " + lastName;
}
}class PersonListLabelProvider extends LabelProvider
{
public String getText(Object element)
{
Person person = (Person) element;
return person.firstName + " " + person.lastName;
}
}
解决方案 »
- Java,两个JPanel之间怎么传值
- 如何把下拉菜单中的选择传递出来?
- 在书中看到:“在一个类的内部不能定义其它类,即类和类之间是平行而非嵌套的关系”
- 致初学者:一个面象对象的"hello world"程序.
- 用java.uitl.zip压缩文件,遇到中文文件名压缩时怎么办?
- 一道java解析字符串,然后以树形结构存入数据库的一道题 --- 各路牛人请搭救一下我吧。
- 菜鸟问题,寻求ceil的例子
- 关于 360度全景的问题?
- 一个关于zip压缩数据流的问题,急急,包送100分
- 急死人的问题哦!GG们帮我想想办法呀~~~~~
- 初始化数组的小问题 来看看啊
- sun.net.ftp.FtpClient 这个类属从哪里获得?
lv.setLabelProvider(new PersonListLabelProvider()); 可是有没有写 ArrayContentProvider() 和 PersonListLabelProvider()
是不是这个原因?