Highlight background colour in a TextEditor, being in a Label, being in a Slider


Hello guys !

I'm creating a custom look and feel with dark colours. One of the controls I'm using is a Slider in LinearBar mode. There is a Label inside which displays the value of the slider. When I double click inside, I can edit the value.

However, after a few failed attempts, I am not able at all to change the colour used for the highlight background. My custom look and feel has been set as the default one, I have changed all the necessary colours Ids in the Slider, Label and TextEditor classes, but without any success.

I guess it would be useful to implement a new ColourId called Label::highlightBackgroundWhenEditingColourId to do that...

Any idea ? Thanks in advance !


Probably what you want to set in your custom Look&Feel is TextEditor::highlightColourId. The Label has a TextEditor inside it, and that's what's drawing the highlighted text stuff.


Hello Timur !

Well, the first thing I have done is to specify a value for the colourId TextEditor::highlightColourId in the definition of my custom look and feel. However it has absolutely no influence on the background colour in this context. I have tried to change the value of a few ColourIds, I have set my custom look and feel as the default one. I have created a "direct" TextEditor in my component and he has the right colour for the highlight background. But in this particular case, the only way I have found to change the colour is to add an instruction in the function "TextEditor* Label::createEditorComponent()". That's why I have suggested that maybe the solution might be to add a new Id called Label::highlightBackgroundWhenEditingColourId, with the associated source code...

As you can see on this picture, the TextEditor on the bottom has a gray background for the highlighted text as I wanted, but in the top control, which is a TextEditor in a Label in a Slider, the colour is wrong...


The function that you are referring to, TextEditor* Label::createEditorComponent(), is virtual and therefore you are free to override it and add whatever behaviour you like. Which is sort of what you are already doing. What's wrong with that?


Well, I have not really overrided the function, I have just said that I have written something in the original JUCE Label class to see what's going on...

I think it would be logical to be able to change the colour of the TextEditor highlight background in JUCE, with a simple instruction in my custom look and feel class, or anywhere, which is the point of the LookAndFeel class.

If I need to override the Label class AND the Slider class just to change a colour, because something is bad about how JUCE is handling the TextEditor::highlightBackgroundColourId, indeed that will work, but this is really wrong isn't it ?


I don't know if this is what you want exactly or if this is even a good way of doing it, but I experimented with this for a minute and was able to change the highlighted color of a linear bar slider. Here's the code I used, which just highlights the background of the text green when it's the slider is clicked on:

class CustomLabel : public Label {
    virtual TextEditor * createEditorComponent() override
        TextEditor* editor = new TextEditor{};
        editor->setColour(TextEditor::highlightColourId, Colours::green);
        return editor;

class CustomLAF : public LookAndFeel_V3 {
    virtual CustomLabel * createSliderTextBox(Slider &) override
        label = new CustomLabel{};
        return label;
    CustomLabel* getSliderCustomLabel() { return label; }
    CustomLabel* label;

Then in the class that contains the slider, I just set the look and feel to a CustomLAF. Is this a step towards what you're after?


Nevermind, I have just found the solution, I had forgotten to set all the colourIds available for the Slider, Label and TextEditor classes.

Anyway, thanks for having spent some time on this guys !