Java SWT: Clear all items in a table before writing

感情迁移 提交于 2019-12-11 04:27:18

问题


How do I clear a table before writing all the rows? The data will be completely different every time I hit this code:

graphicsMemoryTable.setRedraw(false);
int count = 0;
for(int i=0; i<graphicsMemory.size() && count<1000; i+=8,count++)
{
    TableItem item = new TableItem(graphicsMemoryTable, SWT.NONE);
    item.setText(graphicsMemory.get(i).toString());
    item.setText(1,graphicsMemory.get(i+1).toString());
    item.setText(2,graphicsMemory.get(i+2).toString());
    item.setText(3,graphicsMemory.get(i+3).toString());
    item.setText(4,graphicsMemory.get(i+4).toString());
    item.setText(5,graphicsMemory.get(i+5).toString());
    item.setText(6,graphicsMemory.get(i+6).toString());
    item.setText(7,graphicsMemory.get(i+7).toString());
}
graphicsMemoryTable.setRedraw(true);

EDIT: For reference, calling removeAll() worked for me, calling clearAll did not


回答1:


removeAll() method of Table will remove all elements in the table. Here is the javadoc;

public void removeAll()

Removes all of the items from the receiver.




回答2:


You can use table.clearAll();

Clears all the items in the receiver. The text, icon and other attributes of the items are set to their default values. If the table was created with the SWT.VIRTUAL style, these attributes are requested again as needed.



来源:https://stackoverflow.com/questions/37720041/java-swt-clear-all-items-in-a-table-before-writing

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!