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

**URL:** <https://forum.juce.com/t/setting-initial-focus-to-an-editable-combobox-doesnt-work-correctly-in-dialogs/48230>\
**Category:** General JUCE discussion\
**Created:** [October 13, 2021, 12:23pm UTC](https://forum.juce.com/t/setting-initial-focus-to-an-editable-combobox-doesnt-work-correctly-in-dialogs/48230 "2021-10-13T12:23:37Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![benstaton](https://avatars.discourse-cdn.com/v4/letter/b/9fc29f/32.png) [@benstaton](https://forum.juce.com/u/benstaton)\
**Post date:** [October 13, 2021, 12:23pm UTC](https://forum.juce.com/t/setting-initial-focus-to-an-editable-combobox-doesnt-work-correctly-in-dialogs/48230/1 "2021-10-13T12:23:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![ed95](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/ed95/32/7635_2.png) [@ed95](https://forum.juce.com/u/ed95)\
**Post date:** [October 13, 2021, 3:00pm UTC](https://forum.juce.com/t/setting-initial-focus-to-an-editable-combobox-doesnt-work-correctly-in-dialogs/48230/2 "2021-10-13T15:00:33Z")

</div>

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:

> <https://github.com/juce-framework/JUCE/blob/175de90c494c469c88e4944942d1186073a1be10/modules/juce_gui_basics/widgets/juce_Label.cpp#L375>

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.

---

<div class="post-metadata">

**Author:** ![benstaton](https://avatars.discourse-cdn.com/v4/letter/b/9fc29f/32.png) [@benstaton](https://forum.juce.com/u/benstaton)\
**Post date:** [October 14, 2021, 8:31am UTC](https://forum.juce.com/t/setting-initial-focus-to-an-editable-combobox-doesnt-work-correctly-in-dialogs/48230/3 "2021-10-14T08:31:04Z")

</div>

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 🤷‍♂️

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