ListBox redraw problems

Hi,

I have subclassed Component to build a panel that consists of a TableListBox and a few controls to edit the data of the TableListBox.

class RadioPlaylistPanel : public Component , public Button::Listener , public TableListBoxModel

I add the TableListBox like this:

m_table = new TableListBox; addAndMakeVisible (m_table); m_table->setModel (this); ...

In a buttonClicked callback I update my data model and call m_table->updateContent();

The ListBox does not redraw the row which data has changed. Only if I scroll it out of view and back in, or if I select/unselect the row it shows the updated values.

Shouldn’t updateContent() force a redraw of all rows?

Patrick

[code] /** Causes the list to refresh its content.

    Call this when the number of rows in the list changes, or if you want it
    to call refreshComponentForRow() on all the row components.

    This must only be called from the main message thread.
*/
void updateContent();

[/code]

…like it says, that method just forces any custom components to be rebuilt. If you want to repaint the whole thing, just call repaint() !

[quote=“jules”][code] /** Causes the list to refresh its content.

    Call this when the number of rows in the list changes, or if you want it
    to call refreshComponentForRow() on all the row components.

    This must only be called from the main message thread.
*/
void updateContent();

[/code]

…like it says, that method just forces any custom components to be rebuilt. If you want to repaint the whole thing, just call repaint() ![/quote]

Thanks!

I was confused by other documentation, I assumed updateContent would repaint everything:

[code] /** Repaints one of the rows.

    This is a lightweight alternative to calling updateContent, and just causes a
    repaint of the row's area.
*/
void repaintRow (int rowNumber) noexcept;[/code]

or

[code] //==============================================================================
/** This must return the number of rows currently in the table.

    If the number of rows changes, you must call TableListBox::updateContent() to
    cause it to refresh the list.
*/
virtual int getNumRows() = 0;[/code]

Well, I will call repaint() instead of updateContent() which makes a lot of sense because its literally what I want achieve :wink:

Patrick

Fair enough, that other comment is a bit confusing, I should probably rephrase it…

I am now having this same problem but I am calling table.repaint(); Nothing happens. If I click on the header to change the sort it then updates the cells. Calling repaint does not seem to do anything. getNumRows, paintRowBackground and paintCell are never called unless I resize the window or click on the header.

EDIT: Fixed. logic error not calling updateContent() in the right place.

I seem to be having some problems with updating a ListBox too. I'm lessening the number of rows, then calling updateContent() (I tried repaint() too), but it doesn't seem to go away unless I click on all of the rows. 

Edit: Nevermind, this was all my fault. I was only calling updateContent() when i had more than 0 contents to show. Whoops.

Resurrecting this thread: I just hit this, too. If your ListBox doesn’t use custom components, then updateContents() will only update the contents if the number of rows changed, otherwise it does nothing.

It’s possible to work around it, but imho it’s highly counterintuitive that updateContents doesn’t always update the contents!

4 Likes