Setting initial focus to an editable ComboBox doesn't work correctly in dialogs

Hi all,

When opening a JUCE dialog, I’m setting initial focus to its first child component. I’m not doing anything special - the JUCE FocusTraverser takes care of it, and it works fine for the most part.

However, it doesn’t work consistently if the first child component happens to be an editable combobox (ie. a combobox with a built-in text editor).

If the first component is an editable label, the label’s text editor is shown and it receives focus, ready for you to type in.

But if it’s an editable combobox, the combobox gets focused, but its text editor is not shown. If you tab away from the combobox, and then Shift-Tab back to it, its text editor is shown and focused correctly.

As I say, it’s only a problem with editable comboboxes that receive focus when a dialog is first shown. It’s clear there’s a problem because manually focusing it afterwards results in its text editor showing correctly.

Can this be fixed if confirmed, please?

Many thanks!
Ben Staton

ps. I’m testing on Windows, and the combobox is set as editable with a single click.

The standard behaviour for an editable juce::Label is to show the editor when the focus change is initiated from tabbing, so it won’t show its editor when gaining initial keyboard focus:

An editable ComboBox just contains a Label so will have the same behaviour. If you want to force the editor to be shown you can call ComboBox::showEditor() when opening the dialog.

Yes, you’re right @ed95 - my mistake. The label component doesn’t show the editor when initially focused. I even did a quick test to verify. Not sure why I was under the impression it did :man_shrugging:

Thanks for the quick response. I’ll look into manually triggering the editor instead.