# \[solved\] Label .setColour not working, always turns out white no matter what color I set ..?

**URL:** <https://forum.juce.com/t/solved-label-setcolour-not-working-always-turns-out-white-no-matter-what-color-i-set/56784>\
**Category:** General JUCE discussion\
**Created:** [June 23, 2023, 10:27pm UTC](https://forum.juce.com/t/solved-label-setcolour-not-working-always-turns-out-white-no-matter-what-color-i-set/56784 "2023-06-23T22:27:24Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![TrustedSteed](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/trustedsteed/32/13862_2.png) [@TrustedSteed](https://forum.juce.com/u/TrustedSteed)\
**Post date:** [June 23, 2023, 10:27pm UTC](https://forum.juce.com/t/solved-label-setcolour-not-working-always-turns-out-white-no-matter-what-color-i-set/56784/1 "2023-06-23T22:27:24Z")

</div>

I have a regular label:  
`juce::Label currentValueLabel;`

And I’m setting it to what I believe is bright yellow:  
`currentValueLabel.setColour(juce::Label::textColourId, juce::Colour::fromFloatRGBA(0.9f, 0.9f, 0.1f, 0.9f));`

But its not working. Always turns out white. Why?

---

<div class="post-metadata">

**Author:** ![cpr2323](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/cpr2323/32/18682_2.png) [@cpr2323](https://forum.juce.com/u/cpr2323)\
**Post date:** [June 24, 2023, 1:34am UTC](https://forum.juce.com/t/solved-label-setcolour-not-working-always-turns-out-white-no-matter-what-color-i-set/56784/2 "2023-06-24T01:34:02Z")

</div>

I would verify the color first. Put in a known good color, juce::Colours::yellow, and if it works you know to look at why your color is incorrect.

---

<div class="post-metadata">

**Author:** ![andrewj](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/andrewj/32/13428_2.png) [@andrewj](https://forum.juce.com/u/andrewj)\
**Post date:** [June 24, 2023, 2:28am UTC](https://forum.juce.com/t/solved-label-setcolour-not-working-always-turns-out-white-no-matter-what-color-i-set/56784/3 "2023-06-24T02:28:38Z")

</div>

Are you using a custom LookAndFeel which overrides drawLabel() and ignores textColourId?

---

<div class="post-metadata">

**Author:** ![TrustedSteed](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/trustedsteed/32/13862_2.png) [@TrustedSteed](https://forum.juce.com/u/TrustedSteed)\
**Post date:** [June 24, 2023, 3:48pm UTC](https://forum.juce.com/t/solved-label-setcolour-not-working-always-turns-out-white-no-matter-what-color-i-set/56784/4 "2023-06-24T15:48:51Z")

</div>

I tried this ` currentValueLabel.setColour(juce::Label::textColourId, juce::Colours::blue);`  
It still turns out white.  
@andrewj - i don’t have a custom laf for this.

```auto
    currentValueLabel.setText("Current Value", juce::dontSendNotification);
    currentValueLabel.setFont(lcdDigitalFont);
    currentValueLabel.setColour(juce::Label::textColourId, juce::Colours::blue);
    //currentValueLabel.setColour(juce::Label::textColourId, juce::Colour::fromFloatRGBA(0.9f, 0.9f, 0.1f, 0.9f));
    currentValueLabel.setJustificationType(juce::Justification::left);
    addAndMakeVisible(currentValueLabel);

```

` juce::Label currentValueLabel;`  
As far as I am aware the font does not contain any color information.

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [June 24, 2023, 8:49pm UTC](https://forum.juce.com/t/solved-label-setcolour-not-working-always-turns-out-white-no-matter-what-color-i-set/56784/5 "2023-06-24T20:49:29Z")

</div>

It works for me in a new GUI App project.

I guess maybe you should debug into:

```auto
//==============================================================================
void Label::paint (Graphics& g)
{
    getLookAndFeel().drawLabel (g, *this);
}

```

… which, if you indeed have no look and feel applied to the label, should take you into:

```auto
void LookAndFeel_V2::drawLabel (Graphics& g, Label& label)
{
    g.fillAll (label.findColour (Label::backgroundColourId));

    if (! label.isBeingEdited())
    {
        auto alpha = label.isEnabled() ? 1.0f : 0.5f;
        const Font font (getLabelFont (label));

        g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
        g.setFont (font);

        auto textArea = getLabelBorderSize (label).subtractedFrom (label.getLocalBounds());

        g.drawFittedText (label.getText(), textArea, label.getJustificationType(),
                          jmax (1, (int) ((float) textArea.getHeight() / font.getHeight())),
                          label.getMinimumHorizontalScale());

        g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
    }
    else if (label.isEnabled())
    {
        g.setColour (label.findColour (Label::outlineColourId));
    }

    g.drawRect (label.getLocalBounds());
}

```

…where perhaps you can see why your colour is not being applied.

---

<div class="post-metadata">

**Author:** ![TrustedSteed](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/trustedsteed/32/13862_2.png) [@TrustedSteed](https://forum.juce.com/u/TrustedSteed)\
**Post date:** [June 24, 2023, 10:09pm UTC](https://forum.juce.com/t/solved-label-setcolour-not-working-always-turns-out-white-no-matter-what-color-i-set/56784/6 "2023-06-24T22:09:09Z")

</div>

I think I found the issue. Further down the code, I am decreasing the label’s opacity in a `timercallback()`  
The opacity decrease method is **supposed to maintain the RGB** but it seems it doesn’t.

```auto
void myplugin::decreaseOpacityOfCurrentValueLabel()
{

    juce::Colour currentColour = currentValueLabel.findColour(juce::Label::textColourId);

    float currentOpacity = currentColour.getFloatAlpha();

    currentOpacity = std::max(0.0f, currentOpacity - (currentOpacity > 0.6f ? 0.002f : 0.008f));

    juce::Colour newColour = juce::Colour::fromFloatRGBA(currentColour.getFloatRed(), currentColour.getFloatGreen(), currentColour.getFloatBlue(), currentOpacity);

    currentValueLabel.setColour(juce::Label::textColourId, newColour);
}

```

---

<div class="post-metadata">

**Author:** ![stephenk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/stephenk/32/15198_2.png) [@stephenk](https://forum.juce.com/u/stephenk)\
**Post date:** [June 24, 2023, 10:26pm UTC](https://forum.juce.com/t/solved-label-setcolour-not-working-always-turns-out-white-no-matter-what-color-i-set/56784/7 "2023-06-24T22:26:51Z")

</div>

Off the top of my head, I think you could use:

```auto
   currentValueLabel.setColour(juce::Label::textColourId, currentColour.withAlpha(currentOpacity));

```

You can also set the opacity of the entire component directly and leave the color as it is:

```auto
currentValueLabel.setAlpha(/* some number*/)

```

---

<div class="post-metadata">

**Author:** ![TrustedSteed](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/trustedsteed/32/13862_2.png) [@TrustedSteed](https://forum.juce.com/u/TrustedSteed)\
**Post date:** [June 24, 2023, 10:47pm UTC](https://forum.juce.com/t/solved-label-setcolour-not-working-always-turns-out-white-no-matter-what-color-i-set/56784/8 "2023-06-24T22:47:54Z")

</div>

This is working for me - thank you 👍
