'Adapting row height in JFace TableViewer as I scroll my table

I have a JFace TableViewer with an ILazyContentProvider and a StyledCellLabelProvider for each column, which I mostly grabbed from https://wiki.eclipse.org/JFaceSnippets#Snippet006TableMultiLineCells to enable multiline rows. When I open the table, all rows have the height of the row which takes up the most space, as intended. As I scroll down the table, the row heights will change as intended if a row takes up more space. However, this does not currently work in the other direction, i.e., if I scroll so that the current rows showing take up less space, all rows still have the height of the largest row in the whole table.

Is there a way to solve this? Somehow there seems to be a memory of the content that the lazy content provider should be forgetting?

This is my measure method in the StyledCellLabelProvider:

@Override
protected void measure(Event event, Object element) {
    event.width = viewer.getTable().getColumn(event.index).getWidth();
    if (event.width == 0) {
        return;
    }
    TableEntryData rowData = (TableEntryData) element;
    TableCellData cellData = getCellData(rowData, event.index);
    int height = event.gc.textExtent(SOME_STRING).y; // Height of a written string on one line.
    int lines = cellData.getPoints().size();
    event.height = height * lines;

    event.gc.dispose();
}

and this is most of my ILazyContentProvider:

@Override
public void updateElement(int index) {
    viewer.replace(entries.get(index), index);

}

@SuppressWarnings("unchecked") // TODO:
@Override
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
    this.entries = (List<TableEntryData>) newInput;
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source