TableListBox and Components issue

Hi JUCE team. I have a quick question regarding the Components you can use inside a TableListBox.

 

I have a basic TableListBox with column 1 as plain text and column 2 as a ProgressBar. The ProgressBar is used to indicate progress of a file operation.

The TableListBoxModel::refreshComponentForCell looks like this:


Component* TargetComponent::refreshComponentForCell (int rowNumber, int columnId, bool isRowSelected, Component* existingComponentToUpdate) 
{
    if (columnId == 1) 
    {
        jassert(existingComponentToUpdate == nullptr);
        return nullptr;
    }
    if (columnId == 2)
    {
        ProgressBar* bar = static_cast<ProgressBar*>(existingComponentToUpdate);
        if (bar == nullptr)
        {


            bar = new ProgressBar(m_entries[rowNumber]->m_percentage);
        }
        return bar;
    }
    return nullptr;
}

 

When the file progress of 'm_entities[0]' finishes it deletes itself from the array and calls table.updateContent(); The ProgressBar for the second file, which is now entry 0; now doesn't update it's ProgressBar anymore. It looks like the 'existingComponentToUpdate' passed into the refreshComponentForCell() is the pointer to the first entry which is now no longer there.

 

I am obviously doing something wrong here, but not sure what.

 

*bump*

I think I worked it out. I made a ProgressBar wrapper


    class ProgressBarWrapper : public Component
    {
    public:
        ProgressBarWrapper(int row, int column) : m_row(row), m_column(column), m_percentage(0)
        {
            m_bar = new ProgressBar(m_percentage);
            m_bar->setVisible(true);
            addChildComponent(m_bar);
        }
        virtual ~ProgressBarWrapper()
        {
            delete m_bar;
        }
        void resized() override
        {
           m_bar->setBoundsInset(BorderSize<int>(2));
        }
        void UpdatePercentage(double percentage)
        {
            m_percentage = percentage;
        }
        void UpdateRowAndColumn(int row, int column)
        {
            m_row = row;
            m_column = column;
        }
        int GetRow() const { return m_row; }
    private:
        ProgressBar* m_bar;
        double m_percentage;
        int m_row;
        int m_column;
    };

and in the refreshComponentForCell I do ->

 


        ProgressBarWrapper* wrapper = static_cast<ProgressBarWrapper*>(existingComponentToUpdate);
        if (wrapper == nullptr)
        {
            wrapper = new ProgressBarWrapper(rowNumber, columnId);
        }
        else
        {
            if (wrapper->GetRow() == rowNumber)
            {
                wrapper->UpdatePercentage(m_entries[rowNumber]->m_percentage);
            }
            else
            {
                wrapper->UpdateRowAndColumn(rowNumber, columnId);
            }
        }
        return wrapper;

Which seems to work. Is this the correct way of doing it?