# Slider attributes in getLookAndFeel() not set

**URL:** <https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017>\
**Category:** General JUCE discussion\
**Created:** [January 8, 2020, 10:35am UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017 "2020-01-08T10:35:02Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![frodojedi](https://avatars.discourse-cdn.com/v4/letter/f/a5b964/32.png) [@frodojedi](https://forum.juce.com/u/frodojedi)\
**Post date:** [January 8, 2020, 10:35am UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/1 "2020-01-08T10:35:02Z")

</div>

Hi all,  
I want to set the colours of the attributes of my sliders using getLookAndFeel(). I found out that some of the attributes are correctly set (namely `thumbColourId` and `trackColourId`) while others not (namely `textBoxTextColourId`, `textBoxOutlineColourId`, `textBoxHighlightColourId`).

Here my code in the PluginEditor.cpp

```
    void MySynthesizerAudioProcessorEditor::paint (Graphics& g)
{
    g.fillAll (getLookAndFeel().findColour (ResizableWindow::backgroundColourId));
    
    getLookAndFeel().setColour (Slider::thumbColourId, Colours::brown);
    getLookAndFeel().setColour (Slider::textBoxTextColourId, Colours::green);
    getLookAndFeel().setColour (Slider::textBoxHighlightColourId, Colours::yellow);
    getLookAndFeel().setColour (Slider::textBoxOutlineColourId, Colours::purple);
    getLookAndFeel().setColour (Slider::trackColourId, Colours::whitesmoke);
    
}

```

The only way I found to set the unset sliders’attributes is to set directly them where the sliders are created:

```
    FreqSlider.setColour (Slider::textBoxTextColourId, Colours::green);
    FreqSlider.setColour (Slider::textBoxHighlightColourId, Colours::yellow);
    FreqSlider.setColour (Slider::textBoxOutlineColourId, Colours::purple);
    
    
    FreqLabel.setText ("Freq", dontSendNotification);
    FreqLabel.attachToComponent (&FreqSlider, true);
    addAndMakeVisible (FreqLabel);
    FreqSlider.setTextValueSuffix (" Hz");
    addAndMakeVisible (FreqSlider);
    FreqAttachment.reset (new SliderAttachment (valueTreeState, "freq", FreqSlider));

```

Any idea about this strange behaviour?

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [January 8, 2020, 11:01am UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/2 "2020-01-08T11:01:49Z")

</div>

The problem is, that the colour is used in a sub component of the slider, a Label named `valueBox`.  
When you set the colour in the lookAndFeel, no update is triggered, but if you set it to the slider, it will trigger a `colourChanged()`, which triggers a `lookAndFeelChanged()`.

If you call `FreqSlider.lookAndFeelChanged()` in your initial version, you should see the changes taking effect.

Btw, don’t set the colours in paint, just do it once in the constructor. Worst case such a change could trigger a repaint() leaving you in an infinite recursion…

---

<div class="post-metadata">

**Author:** ![frodojedi](https://avatars.discourse-cdn.com/v4/letter/f/a5b964/32.png) [@frodojedi](https://forum.juce.com/u/frodojedi)\
**Post date:** [January 8, 2020, 11:35am UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/3 "2020-01-08T11:35:03Z")

</div>

Thanks a lot Daniel. So what am I supposed to do ultimately?  
As I have various subcomponents of my GUI I would like to set the look and feel and let the other classes inherit it. As I said, for those attributes it works, for the ones related to `valueBox` not.  
So how I can set globally the color of those attributes related to `valueBox`?

Thanks also for the tip of not using paint()

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [January 8, 2020, 11:46am UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/4 "2020-01-08T11:46:14Z")

</div>

In your constructor you set the colours for your lookAndFeel, just as you did.  
After that you can notify the component and all it’s children, that the lookAndFeel changed using [sendLookAndFeelChange()](https://docs.juce.com/develop/classComponent.html#ac314d2449213d7942eca083addfcd097)

```auto
MySynthesizerAudioProcessorEditor::MySynthesizerAudioProcessorEditor (MySynthesizerAudioProcessor& proc) 
: /* ... */
{
    auto& lnf = getLookAndFeel();
    lnf.setColour (Slider::thumbColourId, Colours::brown);
    lnf.setColour (Slider::textBoxTextColourId, Colours::green);
    lnf.setColour (Slider::textBoxHighlightColourId, Colours::yellow);
    lnf.setColour (Slider::textBoxOutlineColourId, Colours::purple);
    lnf.setColour (Slider::trackColourId, Colours::whitesmoke);

    sendLookAndFeelChange();

    setSize (/* ... */);
}

```

EDIT @juce: shouldn’t the lookAndFeel changed be skipped for children, that use their own lookAndFeel?

> <https://github.com/WeAreROLI/JUCE/blob/master/modules/juce_gui_basics/components/juce_Component.cpp#L2100>

shouldn’t it be something like:

```auto
const auto* myLookAndFeel = &getLookAndFeel();
for (int i = childComponentList.size(); --i >= 0;)
{
    auto* child = childComponentList.getUnchecked (i);
    if (&child->getLookAndFeel() == myLookAndFeel) 
        child->sendLookAndFeelChange();

```

---

<div class="post-metadata">

**Author:** ![frodojedi](https://avatars.discourse-cdn.com/v4/letter/f/a5b964/32.png) [@frodojedi](https://forum.juce.com/u/frodojedi)\
**Post date:** [January 8, 2020, 12:13pm UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/5 "2020-01-08T12:13:29Z")

</div>

Indeed the solution you proposed in the previous post does not work.

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [January 8, 2020, 12:17pm UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/6 "2020-01-08T12:17:49Z")

</div>

The one with sendLookAndFeelChanged() after the setColour calls?  
It should actually, the addition was to remove the call from children, that don’t need it, because they have their own lookAndFeel…

Can you try to set a breakpoint in juce\_Slider.cpp

```auto
void lookAndFeelChanged (LookAndFeel& lf)

```

and see if that is called? It is responsible for recreating your textBox, so that the colour settings are propagated…

---

<div class="post-metadata">

**Author:** ![frodojedi](https://avatars.discourse-cdn.com/v4/letter/f/a5b964/32.png) [@frodojedi](https://forum.juce.com/u/frodojedi)\
**Post date:** [January 8, 2020, 1:31pm UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/7 "2020-01-08T13:31:55Z")

</div>

I verified, yes it is called. Yet the texbox color is not changed, it gets the default color (white).

---

<div class="post-metadata">

**Author:** ![spcplugins1](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@spcplugins1](https://forum.juce.com/u/spcplugins1)\
**Post date:** [August 14, 2021, 3:31pm UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/8 "2021-08-14T15:31:56Z")

</div>

Did you ever find an answer to this? I’m having the same problem: I set all the colours in myLookAndFeel, call` LookAndFeel::setDefaultLookAndFeel (&myLookAndFeel);` in the editor constructor, and all the colours are set correctly except for `textBoxOutlineColourId`, which I have to force when adding my sliders, like so:

`mySlider.setColour (Slider::textBoxOutlineColourId, findColour (Slider::textBoxOutlineColourId));`

I don’t understand why this is necessary.

---

<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:** [August 16, 2021, 6:26pm UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/9 "2021-08-16T18:26:35Z")

</div>

This is still a problem. However, another thing you can do is to call sendLookAndFeelChange() on the slider in your parent Component’s constructor after addAndMakeVisible(). Works for me…

i.e:

```auto
addAndMakeVisible(mySlider);
mySlider.sendLookAndFeelChange();

```

---

<div class="post-metadata">

**Author:** ![spcplugins1](https://avatars.discourse-cdn.com/v4/letter/s/45deac/32.png) [@spcplugins1](https://forum.juce.com/u/spcplugins1)\
**Post date:** [August 22, 2021, 10:28am UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/10 "2021-08-22T10:28:04Z")

</div>

Thanks stephenk. This also works for me if I call mySlider.sendLookAndFeelChange() _after_ addAndMakeVisible(). Incidentally, I find there’s a similar problem with ShapeButton.

---

<div class="post-metadata">

**Author:** ![rlg](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/rlg/32/7362_2.png) [@rlg](https://forum.juce.com/u/rlg)\
**Post date:** [October 1, 2021, 8:34pm UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/11 "2021-10-01T20:34:16Z")

</div>

Thank you! I was banging my head against the wall about this unintuitive Slider behaviour. This sendLookAndFeelChange() kludge works.

---

<div class="post-metadata">

**Author:** ![thecargocult](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/thecargocult/32/10988_2.png) [@thecargocult](https://forum.juce.com/u/thecargocult)\
**Post date:** [September 30, 2024, 11:10pm UTC](https://forum.juce.com/t/slider-attributes-in-getlookandfeel-not-set/37017/12 "2024-09-30T23:10:44Z")

</div>

Sorry for the necro, but this is still an issue in juce 8.0.2  
Even the mySlider.sendLookAndFeelChange() suggested above makes no difference for me.

Wasted a lot of time trying to figure it out, then gave up and manually set all the colours directly on all of the slider object. Boring.
