How to add a new row to the top of a Table?

I have a table displaying items in reverse chronological order, so if a new item comes, it has to be displayed as the first row in the table. is there a way to do this?

The method addItemAfter(Object previousItemId) adds the new after the given item, I’m looking for some thing like addItemBefore(Object nextItemId).


Depends on the container implementation. E.g. IndexedContainer has a method addItemAt(int index), but BeanItemContainer doesn’t support it. How about calling container sort after every new item addition.

Hi Johannes, thanks a lot for the help, the IndexedContainer worked for me.

But I have got in to a new issue now
The table component does not support rows of different sizes.
(same as mentioned in this thread).

Anyways thanks :slight_smile:

For BeanItemContainer, I discovered that the following works, but it could be just by accident. Perhaps the frame work swallows a npe, and just puts it at the top by default?

mytable.addItemAfter(null, newItem);