Possible bug in TableListBox


I’m using a TableListBox, from the latest tip. When I get more row than what’s possible on screen (when the scrollbar appear), if I scroll, I get a replication from the first rows, and not the next row as expected.

Here’s an example of TableListBoxModel that show this bug:

int Model::getNumRows ()
    return 15; // Adjust so that the scrollbar appears

void Model::paintRowBackground (Graphics &g, int rowNumber, int width, int height, bool rowIsSelected)
    // Alternate the colours and set the selected row as lightblue
    Colour arr[] = { Colours::white.darker(0.1f), Colours::lightblue.brighter(0.4f), Colours::white.darker(0.2f), Colours::lightblue.brighter(0.4f)};
    g.fillAll(arr[(rowNumber & 1) * 2 + rowIsSelected]);
    g.drawHorizontalLine(height - 1, 0, width);

void Model::paintCell (Graphics &g, int rowNumber, int columnId, int width, int height, bool rowIsSelected) {}

Component * Model::refreshComponentForCell (int rowNumber, int columnId, bool isRowSelected, Component *existingComponentToUpdate)
    if (existingComponentToUpdate) return existingComponentToUpdate;

    case 4:
		return new Label(String("uygu"), String(rowNumber));
        return 0;

void Model::cellClicked (int rowNumber, int columnId, const MouseEvent &e) {}
void Model::cellDoubleClicked (int rowNumber, int columnId, const MouseEvent &e) {}
void Model::backgroundClicked ()
    if (table->getNumSelectedRows())
        SparseSet<int> empty;

void Model::sortOrderChanged (int newSortColumnId, bool isForwards)  {}
// Returns the best width for one of the columns.
int Model::getColumnAutoSizeWidth (int columnId)
       int arr[] = { 120, 250, 100, 120 };
       return arr[columnId - 1];        
const String Model::getCellTooltip (int rowNumber, int columnId)  { return String::empty; }
void Model::tableColumnsChanged (TableHeaderComponent* tableHeader)  {}
void Model::tableColumnsResized (TableHeaderComponent* tableHeader)  {}
void Model::tableSortOrderChanged (TableHeaderComponent* tableHeader)  {}
void Model::selectedRowsChanged (int lastRowSelected) {}
void Model::deleteKeyPressed (int lastRowSelected) {}
void Model::returnKeyPressed (int lastRowSelected) {}
void Model::listWasScrolled () {}

I expect “0” “1” “2” … lines to show up, and they does at start.
However, when scrolling down, the numbers should increase, but instead the revealed part on the bottom of the screen show “0”, “1”… again.

Maybe I’m doing something clumsy ?

if (existingComponentToUpdate) return existingComponentToUpdate;

When it gives you the component to update, you need to actually update it - it might be a row that has been recycled from a different place in the list.

Oh yes, I see it’s smarter than I initially thought about. Thanks.