2009年1月9日

FlexTable 的 clear method

GWT 中的 GridFlexTable 都繼承自 HTMLTable,也就是相對於 HTML 中的 table 標籤。

其中 HTMLTable 有個 clear() method, 使用時要小心。看一下 GWT Javadoc 解釋:

Removes all widgets from this table, but does not remove other HTML or text contents of cells.

意思是說,clear method 只清掉所加入的 widget 而已。所以如果你有為它加 CSS style,比如畫出 td 標籤的邊框。假設原本有 3 筆資料的 table ,clear 後,再加入 1 筆的資料。table 的呈現還是有 3 筆,但下面 2 筆資料都是空白的。

就像這樣



所以原本這樣的寫法

table.clear()

改用 removeRow 土法煉鋼。


while (table.getRowCount() > 0) {
table.removeRow(0);
}