Beginner listbox q

Hey All,

I am trying to get a ListBox component going, but I can’t seem to get it to display. My list uses custom components in rows. Here is the code:

class LayerList :	public Component,
			      public ListBoxModel
	ListBox* list;
	Composition* composition;
	int numRows;
	LayerList(Composition* c);
	int getNumRows();
	void paintListBoxItem(int rowNumber, Graphics &g, int width, int height, bool rowIsSelected);
	Component* refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate);

LayerList::LayerList(Composition* c) {
	composition = c;
	list = new ListBox(T("Layers List"), this);
	DBG("visible content width " + (String)list->getVisibleContentWidth()); //this returns 0... why?

int LayerList::getNumRows() {
	return composition->getNumLayers();

void LayerList::paintListBoxItem(int rowNumber, Graphics &g, int width, int height, bool rowIsSelected) {
	DBG("IN PAINT LIST BOX ITEM");   //this method never seems to get called

Component* LayerList::refreshComponentForRow (int rowNumber, bool isRowSelected, Component* existingComponentToUpdate) {
	if(getNumRows() > 0) { //don't know if this check is really necessary
		LayerLabelComponent* labelComp = (LayerLabelComponent*) existingComponentToUpdate; //my custom component
		if(labelComp == 0) {
			labelComp = new LayerLabelComponent();
		DBG( (String)(composition->getLayer(rowNumber)->getName()));
		return labelComp;
	} else {
		jassert (existingComponentToUpdate == 0);
		return 0;

My class LayerList gets added to a DocumentWindow as its content component somewhere further up the food chain. Anything that is glaringly wrong with the way I am doing things?

If I add a component to the LayerList, say a Button in the constructor (or my custom LayerLabelComponent), it will show up in my window, so it isn’t the way I am adding the component to the window.

Any help appreciated, and thanks.


Nothing looks obviously wrong. Did you setVisible (true) on the row components?

In refreshComponentForRow? yes, no difference. If I need to do that somewhere else, let me know.

Any particular reason why paintListBoxItem doesn’t get called? shouldn’t it be called whenever the ListBox is repainted or updated?

Did you call updateContent() after you create it? If the number of rows changes you need to call that to make it refresh.

i did.

the refreshComponentForRow method is getting called, because I see on the console my “UPDATED…” and “ADDED…” messages. It adds, then it updates. But it doesn’t show them.

It’ll be something really simple, but can’t think what at the moment. The debugger is your friend in this kind of situation…

you haven’t shown your resized() function here - have you got one?

the bit you’ve highlighted in the constructor, about visible width returning 0 - that’s because the listbox hasn’t been given a size yet. could be that you’re not setting a size at all.

ahhhh… that was it.

I am still thinking Java, where there is no resized() business. That tripped me up somewhere else before.

many thanks!