Java 创建简单数据网格时遇到的问题
我只是想熟悉GWT DataGrid,我还阅读了javadoc中给出的示例。奇怪的是,在DataGrid示例中,他们使用的是CellTable 这只是打字错误还是故意的 此外,我还从javadoc复制了以下代码,该代码在CellTable中运行良好,但一旦我用DataGrid替换CellTable,它就会停止工作 非常感谢您的任何建议Java 创建简单数据网格时遇到的问题,java,gwt,Java,Gwt,我只是想熟悉GWT DataGrid,我还阅读了javadoc中给出的示例。奇怪的是,在DataGrid示例中,他们使用的是CellTable 这只是打字错误还是故意的 此外,我还从javadoc复制了以下代码,该代码在CellTable中运行良好,但一旦我用DataGrid替换CellTable,它就会停止工作 非常感谢您的任何建议 public class DataGridPOC implements EntryPoint { DataGrid<Contact> table
public class DataGridPOC implements EntryPoint {
DataGrid<Contact> table = new DataGrid<Contact>();
/**
* A simple data type that represents a contact.
*/
private static class Contact {
private final String address;
private final Date birthday;
private final String name;
public Contact(String name, Date birthday, String address) {
this.name = name;
this.birthday = birthday;
this.address = address;
}
}
/**
* The list of data to display.
*/
private static final List<Contact> CONTACTS = Arrays.asList(
new Contact("John", new Date(80, 4, 12), "123 Fourth Avenue"),
new Contact("Joe", new Date(85, 2, 22), "22 Lance Ln"),
new Contact("George", new Date(46, 6, 6), "1600 Pennsylvania Avenue"));
public void onModuleLoad() {
// Add a text column to show the name.
TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
@Override
public String getValue(Contact object) {
return object.name;
}
};
table.addColumn(nameColumn, "Name");
table.addColumn(nameColumn, "Birthday");
table.addColumn(nameColumn, "Address");
// Set the total row count. This isn't strictly necessary, but it affects
// paging calculations, so its good habit to keep the row count up to date.
table.setRowCount(CONTACTS.size(), true);
// Push the data into the widget.
table.setRowData(0, CONTACTS);
// Add it to the root panel.
RootPanel.get().add(table);
}
}
公共类DataGridPOC实现入口点{
DataGrid table=新的DataGrid();
/**
*表示联系人的简单数据类型。
*/
私有静态类联系人{
私有最终字符串地址;
私人最后日期生日;
私有最终字符串名;
公共联系人(字符串名称、日期、生日、字符串地址){
this.name=名称;
这个生日=生日;
this.address=地址;
}
}
/**
*要显示的数据列表。
*/
私有静态最终列表联系人=Arrays.asList(
新联系人(“约翰”,新日期(80,4,12),“第四大道123号”),
新联系人(“Joe”,新日期(85,2,22),“22 Lance Ln”),
新联系人(“乔治”,新日期(46,6,6),“宾夕法尼亚大道1600号”);
moduleload()上的公共void{
//添加一个文本列以显示名称。
TextColumn name column=新建TextColumn(){
@凌驾
公共字符串getValue(联系人对象){
返回object.name;
}
};
表.addColumn(名称栏,“名称”);
表.addColumn(名称栏,“生日”);
表.addColumn(名称栏,“地址”);
//设置总行数。这不是严格必需的,但会影响
//分页计算,因此保持行计数最新是一个好习惯。
table.setRowCount(CONTACTS.size(),true);
//将数据推送到小部件中。
表.setRowData(0,联系人);
//将其添加到根面板。
RootPanel.get().add(表);
}
}
我认为,这种行为的原因是我们需要明确指定
网格的高度
table.setHeight("300px");
这是我的桌子。这是没有提到的任何地方在报告中。另外,这里的示例使用CellTable代替DataGrid.:)
请随时更正,这可能会对某人有所帮助
谢谢您所说的“停止工作”是什么意思?在数据网格的情况下,表格不会显示。请尝试明确设置高度:table.setHeight(“100px”);看看会发生什么,这不是JavaDoc的问题。如果将表作为层或任何其他向其子级提供大小的小部件添加到可布局中,则无需指定DataGrid的高度。顺便说一下,您不需要设置它的宽度,它就会显示在您的示例中。