我应该使用什么 GWT 小部件来显示 Object 中的字符串属性?

What GWT widget should I use to display String attributes from an Object?

在我的 GWT 应用程序中,我的 onSuccess(Object result) 方法最终检索具有 ArrayList 属性的 Object

此属性包含 Objects 具有字符串属性。

我想在我的 GUI 中显示那些字符串属性,在研究了 CellTable 和其他小部件之后,我找不到一种简单的方法来实现这一点。我似乎无法修改此 CellTable source code example 以满足我的需要。

实现这一目标的最简单方法是什么? (简单的新手语境)。

编辑*每个字符串属性都需要显示在一个带标题的列中,并且会有不止一行信息。

弹性表 http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/FlexTable.html ?

或网格 http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/Grid.html ?

这些本质上是一样的。但是 Grid 更快,但是需要事先知道它的列数和行数。

另一个选项是 CellList<T> - 这使您可以使用某种 List<T> 并提供可以绘制每个项目的单元格。由于它不是为每个项目构建一个小部件,因此它的重量要轻得多,尤其是当您最终要绘制成百上千个项目时。

CellTable<T>DataTable<T>相反,CellList<T>将每个单元格映射到每个项目,而不是假设列表中的每个项目都是一个具有许多属性的对象,每个其中应该放在自己的专栏中。

作为您可能如何绘制每个字符串的示例,com.google.gwt.cell.client.TextCell 知道足以获取每个字符串并按原样自动绘制它,没有自定义样式或任何东西。当您以后需要更多样式时,您可以构建自己的单元格。

带注释的小示例,取自 GWT 的 CellListExample 带注释(并稍作编辑):

// Create a cell to render each value.
TextCell textCell = new TextCell();

// Create a CellList that uses the cell.
CellList<String> cellList = new CellList<String>(textCell);

// 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.
cellList.setRowCount(data.getListOfStrings().size(), true);

// Push the data into the widget.
cellList.setRowData(0, data.getListOfStrings());

// Add the cell list to its parent widget
parent.add(cellList);