paintListBoxitem


#1

Hello,

Could somebody please tell me why paintListBoxItem never gets called here?
It does create a listbox (i guess) because it draws the blue background but I can’t see any row.

LB_ProgramManager.h

//[Headers]     -- You can add your own extra header files here --
#include "juce.h"
//[/Headers]



//==============================================================================
/**
                                                                    //[Comments]
    An auto-generated component, created by the Jucer.

    Describe your class and how it works here!
                                                                    //[/Comments]
*/
class LB_ProgramManager  : public ListBox,
                           public ListBoxModel
{
public:
    //==============================================================================
    LB_ProgramManager ();
    ~LB_ProgramManager();

    //==============================================================================
    //[UserMethods]     -- You can add your own custom methods in this section.
	int getNumRows();
    void paintListBoxItem( int rowNumber, Graphics& g, int width, int height, bool rowIsSelected );
    //[/UserMethods]

    void paint (Graphics& g);
    void resized();


    //==============================================================================
    juce_UseDebuggingNewOperator

private:
    //[UserVariables]   -- You can add your own custom variables in this section.
    //[/UserVariables]

    //==============================================================================


    //==============================================================================
    // (prevent copy constructor and operator= being generated..)
    LB_ProgramManager (const LB_ProgramManager&);
    const LB_ProgramManager& operator= (const LB_ProgramManager&);
};

LB_ProgramManager.cpp

//[Headers] You can add your own extra header files here...
//[/Headers]

#include "LB_ProgramManager.h"


//[MiscUserDefs] You can add your own user definitions and misc code here...
//[/MiscUserDefs]

//==============================================================================
LB_ProgramManager::LB_ProgramManager () : ListBox (T("Programmanager"), 0)
{

    //[UserPreSize]
    //[/UserPreSize]

    setSize (200, 250);

    //[Constructor] You can add your own custom stuff here..

    // tells the ListBox that this object supplies the info about
    // its rows.
    setModel (this);

    setMultipleSelectionEnabled (true);

    //[/Constructor]
}

LB_ProgramManager::~LB_ProgramManager()
{
    //[Destructor_pre]. You can add your own custom destruction code here..
    //[/Destructor_pre]



    //[Destructor]. You can add your own custom destruction code here..
    //[/Destructor]
}

//==============================================================================
void LB_ProgramManager::paint (Graphics& g)
{
    //[UserPrePaint] Add your own custom painting code here..
    //[/UserPrePaint]

    //[UserPaint] Add your own custom painting code here..
	g.fillAll (Colours::black.withAlpha (0.7f));
    //[/UserPaint]
}

void LB_ProgramManager::resized()
{
    //[UserResized] Add your own custom resize handling here..
    //[/UserResized]
}

//[MiscUserCode] You can add your own definitions of your custom methods or any other code here...
void LB_ProgramManager::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
{
    if (rowIsSelected)
        g.fillAll (Colours::lightblue);

        g.setColour (Colours::white);
        g.setFont (height * 0.7f);

        g.drawText (T("Row Number ") + String (rowNumber + 1),
                    5, 0, width, height,
                    Justification::centredLeft, true);
}
int LB_ProgramManager::getNumRows()
{
        return 30;
}
//[/MiscUserCode]

Thank you very much!
Joerg


#2

Thank you guys for your help.

I got it…


#3

You’ve given it your own paint() method, so how do you expect the ListBox to do its painting!?

It’s a really really bad design to make a jucer component inherit from a complex component - put a listbox inside it, but don’t make it a base class!


#4

Jules, what do you expect from a c++ beginner? I make of course stupid mistakes while I try to
understand this language, otherwise I would have my own show in a circus :smiley:

Nevertheless, thank you for your reply…
Joerg


#5

Ah, c++ must be a nightmare as a beginner! I’ve been using it for 15 years and it’s still difficult…