# Check which component has focus

**URL:** <https://forum.inductiveautomation.com/t/check-which-component-has-focus/21297>\
**Category:** Ignition\
**Created:** [December 7, 2018, 10:25pm UTC](https://forum.inductiveautomation.com/t/check-which-component-has-focus/21297 "2018-12-07T22:25:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [December 7, 2018, 10:25pm UTC](https://forum.inductiveautomation.com/t/check-which-component-has-focus/21297/1 "2018-12-07T22:25:50Z")

</div>

Hi Guys,

How can I check which component currently has focus?

Regards,

Dion

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 7, 2018, 10:35pm UTC](https://forum.inductiveautomation.com/t/check-which-component-has-focus/21297/2 "2018-12-07T22:35:25Z")

</div>

```auto
from java.awt import KeyboardFocusManager
focusedComponent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()

```

---

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [December 7, 2018, 10:51pm UTC](https://forum.inductiveautomation.com/t/check-which-component-has-focus/21297/3 "2018-12-07T22:51:29Z")

</div>

> [@paul-griffith](#):
>
> from java.awt import KeyboardFocusManager  
> focusedComponent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()

Does this give the path to the component? If I try to print focusedComponent to the console, it returns 'None'

---

<div class="post-metadata">

**Author:** ![dion.botha](https://avatars.discourse-cdn.com/v4/letter/d/46a35a/32.png) [@dion.botha](https://forum.inductiveautomation.com/u/dion.botha)\
**Post date:** [December 7, 2018, 11:15pm UTC](https://forum.inductiveautomation.com/t/check-which-component-has-focus/21297/4 "2018-12-07T23:15:45Z")

</div>

Sorry, I was doing something wrong… Ok, printing focusedComponent to the console returns this:

com.inductiveautomation.factorypmi.application.components.PMITextField[Username,89,43,149x22,layout=javax.swing.plaf.basic.BasicTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0.0,border=javax.swing.border.CompoundBorder@6e45d33d,flags=296,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=100,height=22],caretColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],disabledTextColor=javax.swing.plaf.ColorUIResource[r=147,g=141,b=130],editable=true,margin=javax.swing.plaf.InsetsUIResource[top=1,left=1,bottom=1,right=1],selectedTextColor=javax.swing.plaf.ColorUIResource[r=0,g=0,b=0],selectionColor=javax.swing.plaf.ColorUIResource[r=250,g=214,b=138],columns=0,columnWidth=0,command=,horizontalAlignment=LEADING]

Is this a string? Doesn’t seem like it, I need to extract the name of the component - in this case - Username.

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [December 7, 2018, 11:30pm UTC](https://forum.inductiveautomation.com/t/check-which-component-has-focus/21297/5 "2018-12-07T23:30:37Z")

</div>

What’s happening there is `print` is calling out the `PMITextField`'s implementation of `toString` - a Java method that just asks the class how to render itself as a string.

`focusedComponent.getName()` or just `focusedComponent.name` would get you a reference to the defined name.
