Set focus on table using key press arrow down

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!

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)