Give Text Field Focus on Window Load

so far I have…

on the Event Handlers Script, visionWindow, visionWindowOpened of my window I have
event.source.getComponent(“rootContainer”).getComponent(“txtTranxferID”).requestFocusInWindow()
this returns, TypeError: getComponent(): 1st arg can’t be coerced to int

When I place this under a button on the same window.
event.source.parent.getComponent(“txtTranxferID”).requestFocusInWindow()
it works as expected. where did I go wrong?

Thanks for the help in advance.

Window objects don’t have named components, so they don’t take strings in their getComponent() methods. What they do have is a rootContainer property. Try this:event.source.rootContainer.getComponent("txtTranxferID").requestFocusInWindow()I’m still not sure it’ll work, though – I don’t remember if components are sufficiently initialized at the window open event to successfully claim focus.

event.source.rootContainer.getComponent("txtTranxferID").requestFocusInWindow()

This does not throw an error but it also does not give my text field focus.

You’ll have to wrap this call in an invokeLater so it gets called once everything else is finished processing:

system.util.invokeLater(system.gui.getParentWindow(event).getComponentForPath('Root Container.txtTranxferID').requestFocusInWindow)
1 Like