I made a cute little window in the Jucer, and it was certainly simple to get the buttons to do what I want, but I’m having fits with ListBoxes. The only way I got one to work was making ListBoxModel public to the main component, which obviously isn’t the way I should be doing things. That’s the way it’s done in the JUCE Demo’s FontsAndTextDemo, but it doesn’t work for me because I need four different ListBoxes going.
So, let me just say what I’m doing. I’ll focus on a single ListBox. Here’s how my ListBox “Generic Component” is setup in the Jucer:
member name = "myListBoxBoards"
name = "my List Box Boards"
virtual class = ""
class = "ListBoxBoards"
constructor params = “”
class ListBoxBoards : public Component,
public ListBoxModel
{
public:
ListBoxBoards();
~ListBoxBoards();
int getNumRows();
void paintListBoxItem( int rowNumber, Graphics& g, int width, int height, bool rowIsSelected );
private:
//ListBox* list;
JGT_BOARD** board;
int numBoards;
void JgtGetBoards( void );
};
ListBoxBoards::ListBoxBoards()
{
//list = new ListBox( T("List Box"), this );
JgtGetBoards(); //builds board array and sets numBoards
}
ListBoxBoards::~ListBoxBoards()
{
for( int i = 0; i < numBoards; i++ )
{
free( board[i]->portSuppressed );
free( board[i] );
board[i] = NULL;
}
free( board );
}
int ListBoxBoards::getNumRows()
{
return numBoards;
}
void ListBoxBoards::paintListBoxItem( int rowNumber, Graphics& g, int width, int height, bool rowIsSelected )
{
if (rowIsSelected)
g.fillAll (Colours::lightblue);
g.drawText ( (board[rowNumber]->sDevType + " " + board[rowNumber]->sLicKey ).c_str(),
4, 0, width - 4, height,
Justification::centredLeft, true );
}
I won’t bother showing all the code that’s getting a list of installed boards in the system. I know that part’s working, because I’ve gotten it working before using the same paintListBoxItem function when I just had one ListBox (and it was public to the main component).
The lines I commented out were just something else I was trying that also wasn’t working. I don’t really know what I’m doing, and I don’t understand the interaction between ListBox and ListBoxModel, and I’m just not figuring things out by cut/pasting other people’s examples (mostly because the only examples I can find are “why is this not working?” posts that don’t show an actual fix).
Thanks for any help!
