Why rowNumber from paintListBoxItem goes from zero to 13 while rowNumber in refreshComponentForRow goes from zero to 14? (crashing my program because 14 doesn’t exist in the owned array called m_Archivos)
If I understand right, existingComponentToUpdate shouldn’t be null when the componet is already created. Then, when I run my program, why I see weirds results when I use this method?
int totalItems = ownedArray.size ();
if (rowNumber >= 0 && rowNumber < totalItems )
// do your thing
It’s a good practice to use these end conditions.
are you setting the number of rows? You can do that using
int TableListBox::getNumRows ( )
Normally components are deleted, when they are no longer shown. If you can keep a break point/logger message in the destructor of “CBrowserItem”,
you can determine whether the items deleted and then recreated.
Uhmm thx for your answer! however that didn’t solve the problem:
Component* CBrowserModelo::refreshComponentForRow(int rowNumber, bool isRowSelected, Component *existingComponentToUpdate)
{
int TotalItems = m_Archivos->Tamaño(); //Tamaño return the size of the owned array
if (rowNumber >=0 && rowNumber<TotalItems)
{
if (existingComponentToUpdate == 0)
{
return new CBrowserItem(m_Archivos->NombreArchivo(rowNumber));
}
else
{
return existingComponentToUpdate;
}
}
}[/code]
Now I get an exception in this Component method:
[code]void Component::addAndMakeVisible (Component* const child, int zOrder)
{
if (child != 0)
{
child->setVisible (true); //here I get the exception!
addChildComponent (child, zOrder);
}
}
Component* CBrowserModelo::refreshComponentForRow(int rowNumber, bool isRowSelected, Component *existingComponentToUpdate)
{
int TotalItems = m_Archivos->Tamaño(); //Tamaño return the size of the owned array
if (rowNumber >= 0 && rowNumber < TotalItems)
{
if (existingComponentToUpdate == 0)
{
existingComponentToUpdate = new CBrowserItem(m_Archivos->NombreArchivo(rowNumber));
}
}
else
existingComponentToUpdate = 0L;
return existingComponentToUpdate;
}
It’s simpler to debug, if your method has single return statement.
put a logger message in “getNumRows ( )” method and check what do you return 13 or 14. It should be 13.
Deletion :
Everytime you resize the window containing the listbox or scroll up/down components shown in the list box are deleted.
Let us assume that 10 rows are visible
Now if the window is resized(made smaller), and only 3 rows visible, juce would delete 5 rows, sparing 3 rows which are visible plus two other which follow the visible rows.
Now again if you resize the window(made bigger), making 10 rows visible juce has to create these components again. This is the reason components are created repeatedly on window resize and listbox scroll.
Great. I got a lot of help when I had problem. Just returning a favour I got from others.