Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
ArrayContainer wrapper
I've been thinking of publishing this simple, yet often useful wrapper for a while. And damn, Sami made an almost identical wrapper today as well... :huh:
Anyhow, here's my version. You can use it easily, for example:
// An array
Integer[] numbers = {4, 8, 15, 16, 23, 42};
// The wrapper
ArrayContainer<Integer> numberCtn = new ArrayContainer<Integer> (numbers);
// The column property ID is used by Table as the default for
// column header. It is by default "0".
numberCtn.setColumnPropertyId("Number");
// Use the wrapper as the data source for the table
Table numbersTbl = new Table("Integers", numberCtn);
mainWindow.addComponent(numbersTbl);
See the
- On-line Demo
- API Documentation
- The project page that has a bit more code examples and the download link
I added a LazyContainer class suggested by Sami. It allows fully dynamic generation of container data from a callback interface. It's also a much easier alternative to Table.ColumnGenerator for calculating the values of one column from another.
// 100,000 rows and 2 columns
LazyContainer lazydata = new LazyContainer(100000, 2, new LazyContainer.Provider() {
public Object getData(int row, int column) {
if (column == 0)
return row;
else if (column == 1)
return ((double)row)*((double)row);
else
return null;
}
});
Table table = new Table("Data from a Lazy Container", lazydata);
table.setColumnHeaders(new String[] {"Index", "Power of Index"});
mainWindow.addComponent(table);
Notice that a Table is unable to hold more than about 500,000 items. The exact limit depends on the font size, because the table content is rendered as a very tall HTML layer.
For more details, see the:
The LazyContainer is included in the new [tt]arraycontainer-0.1.1.jar[/tt].
Created http://dev.vaadin.com/ticket/4220 for the above mentioned 500.000 rows limitation.