# Label texteditor colour

**URL:** <https://forum.juce.com/t/label-texteditor-colour/7893>\
**Category:** General JUCE discussion\
**Created:** [December 20, 2011, 12:45am UTC](https://forum.juce.com/t/label-texteditor-colour/7893 "2011-12-20T00:45:12Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![AaronLeese](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aaronleese/32/624_2.png) [@AaronLeese](https://forum.juce.com/u/AaronLeese)\
**Post date:** [December 20, 2011, 12:45am UTC](https://forum.juce.com/t/label-texteditor-colour/7893/1 "2011-12-20T00:45:12Z")

</div>

I just noticed that when you click on a label it creates a textEditor and the text in that editor (once you type some) is black (regardless of the lookAndFeel colour settings).

If selected, it changes to the proper TextEditor highlightedTextColourId colour, but then goes back to black if you start typing.  
Once the label loses focus it goes to the Label::textColourId of course.

Anyway, that’s different from how textEditors behave and seems kinda wonky.

Here’s what I have in my LookAndFeel class. Let me know if there is some colour I am missing that would override that white.

```auto
setColour(Label::textColourId, Colours::greenyellow); 
setColour(Label::outlineColourId, Colours::grey);
    
setColour(TextEditor::highlightedTextColourId, Colours::red);
setColour(TextEditor::highlightColourId, Colours::darkgrey);
setColour(TextEditor::textColourId, Colours::greenyellow);
setColour(TextEditor::backgroundColourId, Colours::black);
```

---

<div class="post-metadata">

**Author:** ![AaronLeese](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aaronleese/32/624_2.png) [@AaronLeese](https://forum.juce.com/u/AaronLeese)\
**Post date:** [December 29, 2011, 12:30am UTC](https://forum.juce.com/t/label-texteditor-colour/7893/2 "2011-12-29T00:30:46Z")

</div>

Ok - here is the ISSUE and FIX:

TextEditors that are created from Labels don’t get all the proper color (err … colour) info from the Label’s set LookAndFeel. So, if I override the drawLabel method in my lookAndFeel class I can change this colour.

In other words … simply doing:

```auto

myLookAndFeel::myLookAndFeel() 
{
     setColour(TextEditor::textColourId, Colours::greenyellow);
}
```

does NOT propagate to textEditors created from Labels that have inherited that style.

Instead we use a hack …

[code]  
void StyleSheet::drawLabel (Graphics& g, Label& label)  
{

```
// HACK !!!!
label.setColour (TextEditor::textColourId, Colours::greenyellow);

```

… now it works

}[/code]

---

<div class="post-metadata">

**Author:** ![Shlomi](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/shlomi/32/99_2.png) [@Shlomi](https://forum.juce.com/u/Shlomi)\
**Post date:** [December 30, 2011, 9:12am UTC](https://forum.juce.com/t/label-texteditor-colour/7893/3 "2011-12-30T09:12:11Z")

</div>

Why not using a TextEditor in the first place? you can configure it to look like a label and basically you’re done, right?

---

<div class="post-metadata">

**Author:** ![liamtmlacey](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/liamtmlacey/32/82_2.png) [@liamtmlacey](https://forum.juce.com/u/liamtmlacey)\
**Post date:** [July 17, 2012, 4:47pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/4 "2012-07-17T16:47:01Z")

</div>

Thanks for this fix Aaron, this issue was driving me insane.

---

<div class="post-metadata">

**Author:** ![AaronLeese](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aaronleese/32/624_2.png) [@AaronLeese](https://forum.juce.com/u/AaronLeese)\
**Post date:** [December 8, 2012, 6:12pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/5 "2012-12-08T18:12:50Z")

</div>

Just found this post after coming onto this problem again. Wow … so weird to search the forum and find the answer in your own post, eh?

Jules - what about adding something to get the Label’s textEditors to use the DefaultLookAndFeel ?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 8, 2012, 9:42pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/6 "2012-12-08T21:42:00Z")

</div>

> [@](#):
>
> what about adding something to get the Label’s textEditors to use the DefaultLookAndFeel ?

Sorry, don’t understand what you mean…?

---

<div class="post-metadata">

**Author:** ![AaronLeese](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aaronleese/32/624_2.png) [@AaronLeese](https://forum.juce.com/u/AaronLeese)\
**Post date:** [December 24, 2012, 8:59pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/7 "2012-12-24T20:59:07Z")

</div>

So … if you specify TextEditor colors in a LookAndFeel object, and then set that LookAndFeel as the default for a project, then create a label, you will notice that the textEditor created by the label (when it is double clicked on) does NOT use the specified LookAndFeel.

Similarly, some elements created by various custom dialogs (file browsers, etc) don’t use certain LookAndFeel Colors that you would expect them to use (the file browser created from the PluginBrowser object is one).

I’ve fixed this where I could in my LookAndFeel class with things like:

```auto

void StyleSheet::drawLabel (Graphics& g, Label& label) {
     
    label.setColour (TextEditor::textColourId, findColour(TextEditor::textColourId));

```

And also by setting the LookAndFeel of dialog boxes after creating them.

But really - they should default to using the “default” look and feel.

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [December 29, 2012, 12:28pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/8 "2012-12-29T12:28:22Z")

</div>

> [@](#):
>
> if you specify TextEditor colors in a LookAndFeel object, and then set that LookAndFeel as the default for a project, then create a label, you will notice that the textEditor created by the label (when it is double clicked on) does NOT use the specified LookAndFeel.

No, not true - it definitely does use the normal l+f. But it does inherit any expliticly-specified colours from the label, so that it matches it. Have a look at Label::createEditorComponent(), and maybe override that if you want to avoid those colours being inherited.

---

<div class="post-metadata">

**Author:** ![AaronLeese](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aaronleese/32/624_2.png) [@AaronLeese](https://forum.juce.com/u/AaronLeese)\
**Post date:** [January 19, 2013, 5:17pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/9 "2013-01-19T17:17:56Z")

</div>

No, let me rephrase this …

In the constructor for Label(), it sets some colours …

from juce\_label:

```auto
    setColour (TextEditor::textColourId, Colours::black);
    setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
    setColour (TextEditor::outlineColourId, Colours::transparentBlack);
```

This is annoying, since it makes it impossible to set the default color for the textEditors that are created by Labels (the text is always black). Couldn’t you use findColour() instead, and set Labels to create textEditors with the default Texteditor textColour?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 19, 2013, 10:23pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/10 "2013-01-19T22:23:30Z")

</div>

That wouldn’t really work, because if needs to override the colours in the default l+f… Why not call Component::removeColour() to clear those from your label?

---

<div class="post-metadata">

**Author:** ![AaronLeese](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aaronleese/32/624_2.png) [@AaronLeese](https://forum.juce.com/u/AaronLeese)\
**Post date:** [January 20, 2013, 9:10pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/11 "2013-01-20T21:10:45Z")

</div>

Yeah, there are a bunch of ways to do it individually, on each Label.  
There really should be a way to set the textColor globally though, right?

Overriding it in the default l+f currently doesn’t work either, since it literally specifies Colours::black in the Label constructor.

What if you made the Label constructor use the default l+f instead of Colours::black, then it would be easy enough to specify the Color in the default l+f, yeah?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [January 22, 2013, 10:12am UTC](https://forum.juce.com/t/label-texteditor-colour/7893/12 "2013-01-22T10:12:31Z")

</div>

> [@](#):
>
> What if you made the Label constructor use the default l+f instead of Colours::black, then it would be easy enough to specify the Color in the default l+f, yeah?

Well, there’s only one default l+f globally, but the label wants its text box to have a different background colour to the default one (i.e. it wants it to match the label’s background colour).

---

<div class="post-metadata">

**Author:** ![AaronLeese](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aaronleese/32/624_2.png) [@AaronLeese](https://forum.juce.com/u/AaronLeese)\
**Post date:** [January 24, 2013, 2:50am UTC](https://forum.juce.com/t/label-texteditor-colour/7893/13 "2013-01-24T02:50:53Z")

</div>

No no … we’re not talking about the background colour … that does match (the Label BG, as it should).

But the TEXT colour does not. Text colours in Label created textEditors are always BLACK! Which is annoying if you are doing a dark background color scheme!

just sayin’

---

<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:** [January 24, 2013, 3:59am UTC](https://forum.juce.com/t/label-texteditor-colour/7893/14 "2013-01-24T03:59:29Z")

</div>

Hi Aaron, you need to set textBoxTextColourId - take a look inside createSliderTextBox().

---

<div class="post-metadata">

**Author:** ![AaronLeese](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aaronleese/32/624_2.png) [@AaronLeese](https://forum.juce.com/u/AaronLeese)\
**Post date:** [January 29, 2013, 1:38am UTC](https://forum.juce.com/t/label-texteditor-colour/7893/15 "2013-01-29T01:38:48Z")

</div>

I wasn’t actually talking about Slider related textboxes, just ones created from a normal Label.

But yeah, I see that the slider related Labels and Textboxes use the TextBoxColour Ids (as one might expect).

Uncustomized Labels however, do not.

Really, it doesn’t matter much to me, I have this working by overriding a bunch of LookAndFeel methods.

But for the novice, it seems confusing that you can specify every Label and TextEditor related colour, and still get black text when you edit the label. I know it took me a long time to figure out how to override that when I first looked at it.

Anyway, no worries.

---

<div class="post-metadata">

**Author:** ![daven](https://avatars.discourse-cdn.com/v4/letter/d/59ef9b/32.png) [@daven](https://forum.juce.com/u/daven)\
**Post date:** [February 7, 2013, 2:12pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/16 "2013-02-07T14:12:36Z")

</div>

So which looks and feels need to be overridden? Just DrawLabel? Because that hadn’t solved if for me. It looks like the drawing of the text is done in the TextEditor when it’s being edited, as it has to break text up into regions of contiguous style (i.e. selected vs unselected parts). I tried hacking that a bit but hopefully you’ve got an easier way Aaron?

---

<div class="post-metadata">

**Author:** ![widdershins](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/widdershins/32/20_2.png) [@widdershins](https://forum.juce.com/u/widdershins)\
**Post date:** [February 11, 2013, 8:14pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/17 "2013-02-11T20:14:45Z")

</div>

Just wanted to chime in that I just encountered this problem, and found this thread, so Jules, would be good if you take a look, seems to be a common point of confusion. Just to clarify what the problem is, if you create a Label that has been .setEditable (true, false, true), when you click the Label, the resulting editor’s text is always black. Confused me for a good half an hour.

---

<div class="post-metadata">

**Author:** ![AaronLeese](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/aaronleese/32/624_2.png) [@AaronLeese](https://forum.juce.com/u/AaronLeese)\
**Post date:** [February 13, 2013, 10:36pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/18 "2013-02-13T22:36:54Z")

</div>

Yeah, just overriding drawLabel as shown further up in this thread will solve this. Not so elegant, but hey.

---

<div class="post-metadata">

**Author:** ![jimc](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/jimc/32/16067_2.png) [@jimc](https://forum.juce.com/u/jimc)\
**Post date:** [June 23, 2014, 5:38pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/19 "2014-06-23T17:38:17Z")

</div>

Bump! &nbsp;I was just driving myself round in circles trying to figure out what I'd done wrong. This could use a fix maybe?

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [June 29, 2014, 3:04pm UTC](https://forum.juce.com/t/label-texteditor-colour/7893/20 "2014-06-29T15:04:35Z")

</div>

Is there really a bug that needs fixing here? Some people will want to be able to specify a different colour for the text when it's being edited, so having two text colour settings doesn't seem like a problem to me.

e.g.

```
label.setColour (Label::textColourId, Colours::red);
        label.setColour (TextEditor::textColourId, Colours::blue);
```

..would give you a red label that changes to blue text when edited.

I guess I could add some extra logic to see whether a TextEditor::textColourId&nbsp;colour has been specified, and to default to the label colour if not, but it all gets a bit hairy because there are per-component and per-lookandfeel colour settings, so someone may want to use the editor colour that's specified by their&nbsp;L+F, but still want to override&nbsp;the label colour in the component.

[Next page](https://forum.juce.com/t/label-texteditor-colour/7893.md?page=2)
