I have 2 ArrayLists that I want to display at alternate times. I have a button that when clicked should swap out the first list for the second list.
I have tried 2 approaches with little success.
The first approach was to create a ListDataProvider and bind it to the list and table, but when the button was clicked and the list structure changed nothing happened./
My second approach was to stick with the normal CellList and simply reset the row count and row data. This approach works if I click my button twice.
What could i be overlooking? Any help will be much appreciated!
Code is as follows:
This is when I try re add the ArrayList to the CellList
public void refreshTable()
{
systemTable.setRowCount(SYSTEMS.size(), true);
systemTable.setRowData(0, SYSTEMS);
}
I tried it with the ListDataProvider as follows:
private ListDataProvider<String> listDataProvider = new ListDataProvider<String>(SYSTEMS);
public void refreshTable()
{
listDataProvider.refresh();
}
You are probably running into this issue.
Both versions should work.
For the first solution try to reverse the calls (call first setRowData()
and then setRowCount()
):
public void refreshTable()
{
systemTable.setRowData(0, SYSTEMS);
systemTable.setRowCount(SYSTEMS.size(), true);
}
for the second solution I think you forgot to call addDataDisplay
.
Here are some ways to change the underlying data:
1.) create a new ListDataProvider and set the DataDisplay
(you don't need to call refresh):
private ListDataProvider<String> listDataProvider = new ListDataProvider<String>(SYSTEMS);
listDataProvider.addDataDisplay(systemTable);
2.) set a new list of the existing ListDataProvider:
listDataProvider.setList(SYSTEMS);
3.) modify the existing list:
listDataProvider.getList().add/remove etc