# Focus on Label Component in DialogWindow

**URL:** <https://forum.juce.com/t/focus-on-label-component-in-dialogwindow/20457>\
**Category:** General JUCE discussion\
**Created:** [January 1, 2017, 3:49pm UTC](https://forum.juce.com/t/focus-on-label-component-in-dialogwindow/20457 "2017-01-01T15:49:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nammick](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nammick/32/2169_2.png) [@nammick](https://forum.juce.com/u/nammick)\
**Post date:** [January 1, 2017, 3:49pm UTC](https://forum.juce.com/t/focus-on-label-component-in-dialogwindow/20457/1 "2017-01-01T15:49:21Z")

</div>

I have a dialog window that accepts a custom component which in tern has an editable label. For ease of use to the user I want the key cursor blinking and the label ready to accept input for speed save the user clicking on the label component.

I have read in previous posts that the label needs to be displayed before calling for focus.  
My code calls this at time of creation

iptBox-\>grabKeyboardFocus();  
iptBox-\>setWantsKeyboardFocus(true);

And I have tried those post the dialogWindow being shown.

I have also tried bringing the window to the front with this  
savePresetWindow-\>toFront(true);

Then calling the above but can’t seem to gain focus… Am I missing something.

PS Jules shouldn’t answer as he promptly answered a question on Christmas Eve and New Years Eve…

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [January 1, 2017, 6:39pm UTC](https://forum.juce.com/t/focus-on-label-component-in-dialogwindow/20457/2 "2017-01-01T18:39:07Z")

</div>

> [@IanKnowles](#):
>
> I have read in previous posts that the label needs to be displayed before calling for focus.My code calls this at time of creation

Create a Timer and in the callback set the focus.

Also check out [this thread](https://forum.juce.com/t/how-to-highlight-select-the-text-in-a-texteditor-in-an-alertwindow/20028/7) in case it’s relavent.

Rail

---

<div class="post-metadata">

**Author:** ![nammick](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nammick/32/2169_2.png) [@nammick](https://forum.juce.com/u/nammick)\
**Post date:** [January 1, 2017, 8:44pm UTC](https://forum.juce.com/t/focus-on-label-component-in-dialogwindow/20457/3 "2017-01-01T20:44:51Z")

</div>

Ok well I’ll test the using a timer callback. I have a polling system which is governed by an event timer callback anyway as I am using quite bit of threading in the application.

Had a read through some of the pointers in your post which I agree with however I should have pointed out that my application is standalone audio not a plugin, I would have gone down the component overlay model if it were but as its an app I wanted a separate window and focus for ease and with Return Key to finish input and close dialog which I have. Im just trying to make it as easy as possible from a UX perspective. Will let you know if the timer triggered focus works as there is only the one textbox in the window. Cheers.

---

<div class="post-metadata">

**Author:** ![nammick](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nammick/32/2169_2.png) [@nammick](https://forum.juce.com/u/nammick)\
**Post date:** [January 1, 2017, 8:50pm UTC](https://forum.juce.com/t/focus-on-label-component-in-dialogwindow/20457/4 "2017-01-01T20:50:54Z")

</div>

Ah ok so this actually pulls keyboard focus away (after mouse click and “is timer” is showing on my console so I know its grabKeyboardFocus function is the culprit. iptBox is Label component so does it have a child component I need to target?

```
InputDialogComponent::InputDialogComponent()
{
   startTimer(50);
}
InputDialogComponent::~InputDialogComponent()
{
    stopTimer();
}
void InputDialogComponent::timerCallback()
{
    std::cout << " is timer " << std::endl;
    iptBox->grabKeyboardFocus();
}
```

---

<div class="post-metadata">

**Author:** ![nammick](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/nammick/32/2169_2.png) [@nammick](https://forum.juce.com/u/nammick)\
**Post date:** [January 1, 2017, 9:12pm UTC](https://forum.juce.com/t/focus-on-label-component-in-dialogwindow/20457/5 "2017-01-01T21:12:31Z")

</div>

K, Figured it, this feels a little dirty but it works so unless any better suggestions Im rolling with showEditor() call in timed callback then stoping the timer…

```
void InputDialogComponent::timerCallback()
{
    std::cout << " is timer " << std::endl;
    iptBox->showEditor();
    stopTimer();
}
```

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [January 1, 2017, 11:54pm UTC](https://forum.juce.com/t/focus-on-label-component-in-dialogwindow/20457/6 "2017-01-01T23:54:41Z")

</div>

That looks right to me.

Cheers,

Rail
