I met a problem about how to update the data in table by thread.
First, I create a component:
VerticalSplitPanel vsplit = new VerticalSplitPanel();
[b]
[color=#fc0404]
[/color]Second, I create a table and add the table to vsplit by addComponent();The table’s code are below:
[/b]
[code]
Table table = new Table();
table.setSizeFull();
table.setSelectable(true);
table.setImmediate(true);
IndexedContainer c = new IndexedContainer();
c.addContainerProperty(APPLIST_PROPERTY_ID, Integer.class, null);
c.addContainerProperty(APPLIST_PROPERTY_APPNAME, String.class, null);
//connect data source
table.setContainerDataSource(c);
//set column headers
table.setColumnHeaders(column);
[/code]
[b]
[color=#fc0404]
[/color]Third, I add datas to table:(here I add one Item in table, just for test)
[/b]
Container c = table.getContainerDataSource();
Object itemId = c.addItem();
Item item = c.getItem(itemId);
item.getItemProperty(APPLIST_PROPERTY_ID).setValue(a.getId());
item.getItemProperty(APPLIST_PROPERTY_APPNAME).setValue(a.getAppName());
[b]
[color=#fc0404]
[/color]Fourth, I need to update the data per 3 seconds, so , I made this class implements Runnable interface and implements the run()method.
[/b]
[code]
public void run() {
while(true){
try {
//update the data in table
table.removeAllItems();
//In here, suppose that I get a Object b from database, I need delete all data in table, and add the newly data in table
Container c = table.getContainerDataSource();
Object itemId = c.addItem();
Item item = c.getItem(itemId);
item.getItemProperty(APPLIST_PROPERTY_ID).setValue(b.getId());
item.getItemProperty(APPLIST_PROPERTY_APPNAME).setValue(b.getAppName());
Thread.sleep(3000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
[/code]
Unfortunately,I met two problems :
One: the table’s data still hold the old data and the newly data isn’t display, why?
Two: if you click the item in table, the data will update and display the newly data, why?
How could I solve those problems? Can you help me? Thanks!