# Set focus on table using key press arrow down

**URL:** <https://forum.inductiveautomation.com/t/set-focus-on-table-using-key-press-arrow-down/10090>\
**Category:** Ignition\
**Created:** [June 4, 2015, 3:33am UTC](https://forum.inductiveautomation.com/t/set-focus-on-table-using-key-press-arrow-down/10090 "2015-06-04T03:33:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ella\_ramos](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ella_ramos/32/3455_2.png) [@ella\_ramos](https://forum.inductiveautomation.com/u/ella_ramos)\
**Post date:** [June 4, 2015, 3:33am UTC](https://forum.inductiveautomation.com/t/set-focus-on-table-using-key-press-arrow-down/10090/1 "2015-06-04T03:33:55Z")

</div>

I’m trying to create a search function using a textbox and a table.

Current focus is on the text box, i want to be able to set the focus on the table when i click arrow down and without clicking the table below the text box.

Thanks!

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [June 4, 2015, 12:39pm UTC](https://forum.inductiveautomation.com/t/set-focus-on-table-using-key-press-arrow-down/10090/2 "2015-06-04T12:39:39Z")

</div>

I’m also assuming that you want to navigate the table with the keyboard as well. That makes even more difficult, since just giving focus to the table does not confer focus to a cell:

(keyPressed event)

`if event.keyCode == event.VK_DOWN:
    t=event.source.parent.getComponent('Table')
    t1=t.getTable()
    t1.changeSelection(0,0,False,False)
    t.requestFocus()`

Instead, I grabbed the screen location of the underlying JTable, then use Robot to click the top cell. The second mouseMove() puts the mouse back to its original location:

(keyPressed event)

`if event.keyCode == event.VK_DOWN:
  from java.awt import Point, Robot, MouseInfo
  from java.awt.event import InputEvent
  from javax.swing import SwingUtilities as SU
  c=event.source.parent.getComponent('Table').getTable()
  r=Robot()
  p=c.getLocationOnScreen()
  p1=MouseInfo.getPointerInfo().getLocation()
  print p, p1
  r.mouseMove(p.x, p.y)
  r.mousePress(InputEvent.BUTTON1_MASK)
  r.mouseRelease(InputEvent.BUTTON1_MASK)
  r.mouseMove(p1.x, p1.y)`
