Styling Issue for Editable ComboBox

Hi there,
Trying to change the text colour of a ComboBox (the text colour that is displayed while you are actually writing text) and cannot find a way to have it shown other than white.

Tried all the possible (AFAIK) setColour calls, i.e. (using red just for testing)

addAndMakeVisible (&myEditableComboBox);
myEditableComboBox.addItemList (myValuesStringArray);
myEditableComboBox.setSelectedItemIndex(0);
myEditableComboBox.setEditableText (true);
myEditableComboBox.setColour (ComboBox::textColourId, Colours::red);
myEditableComboBox.setColour (Label::textColourId, Colours::red);
myEditableComboBox.setColour (Label::textWhenEditingColourId, Colours::red);
myEditableComboBox.setColour (TextEditor::textColourId, Colours::red);

with no success. if you start editing + are in the process of writing text your text is white :frowning:

Investigating into juce code I see that and editable ComboBox happens to be a ComboBox containint a Label containing a TextEditor - tried to manually change all the graphics.setColour() calls inside the textEditor and I saw that the call that makes the editing text change color is at line 521 of juce_TextEditor.cpp (using juce 5.4.5)

My next Step will be to try an editable Label to see if removing an element in the chain I can have the editing text colour work … but I suspect either I made a silly mistake or there’s a gap between the colour settings of a ComboBox and the resulting styling of the TextEditor “grandchildren”

Has anyone had this same issue - Is there a quick fix on the code to make it work?

thanks!

ok workaround is to set e.g.

setColour (Label::textWhenEditingColourId, Colours::red);

in the constructor of the L&F used as default in my case.
SetColour directly on the ComboBox component does not seem to work tough - so maybe there’s a gap here.

The colour set on the component itself is not inherited. But the colour of the lookandfeel is, so did you try this?

myEditableComboBox.getLookAndFeel().setColour (Label::textWhenEditingColourId, Colours::red);
1 Like

awesome! that might be another way to do this.
Would love tough to be able to style those components fully (with their own siblings in one shot) or maybe a nice juce feature could be to set a l&f on a component specifying to forward to all its “Siblings” i.e. all the “addedAndMadeVisible” of that component.

1 Like

That’s how my PluginGuiMagic works :slight_smile:

CSS classes define colours and can be referenced, and you can even choose from different LookAndFeels.

2 Likes

I haven’t read the full topic but consider writing a setColurRecursive () that sets the given Colour for the specified colourId on a Component and all its children.
Sure it’s overkill, but those Components that don’t use that colourId will simply ignore it so… it may work!