0

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;
}

1 Answer 1

0

The measure item code in the Table class (used by TableViewer) will never reduce the size of rows once it has grown bigger, so there is no way to change this.

The measure code is Table.sendMeasureItem but it can't be overridden. The code here is platform specific, but I checked both the Windows and macOS version (not sure about the Linux/GTK version).

I do have a hack to work around this, but it is platform dependent and I only have it for macOS.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.