Label isn't visible


#1

So I am really new to juce, so I know this is something really simple that I'm missing, but I can't figure out how to make my label visible.

 

To add a button, I just do this:

 

MainContentComponent::MainContentComponent()

{

    setSize(300, 300);

    button1 = new TextButton("Button 1");

    button1->setBounds(20, 70, 260, 20);

    addAndMakeVisible(button1);

}


void MainContentComponent::paint (Graphics& g)

{

    g.fillAll (Colour (0xffffffff));

    addAndMakeVisible(button1);

}

 

This works great, but when I do the exact same thing with a label, it doesn't work.

 

MainContentComponent::MainContentComponent()

{

    setSize (300, 300);


    label1  = new Label("I am a label. ");

    

    label1 ->setBounds(10, 10, 150, 20);

    label1->setFont(Font(16.0));



    addAndMakeVisible(label1);

}


void MainContentComponent::paint (Graphics& g)

{

    g.fillAll (Colour (0xffffffff));

    addAndMakeVisible(label1);

}

 

What am I missing?


#2

The constructor for Label is :

Label (const String &componentName=String::empty, const String &labelText=String::empty)

So the text you are passing into it won't be the text for the label and I suppose that will make it look like it's invisible. I think you can just pass an empty string for the componentName and the desired initial text as the second argument for the constructor.


label1 = new Label("","I am a label. ");
 


#3

Ahh, thankyou. I new it was something painfully simple like that.