Setting focus or remove ability to recieve focus

I have a window with many components on it. There is a submit button at the bottom of the screen. After it is press the focus returns to the top left input box on screen. I would really like it to set focus to no component on screen, then user can click into which component they want to change.

Is the submit button closing/opening a screen? I’m confused why the button itself wouldn’t retain the focus after being pressed.

Focus is a strange animal. There isn’t really a way to have nothing have focus. The best bet is to have something take the focus that isn’t so obvious (like a blinking cursor in a text field)

All components have a function on them called requestFocusInWindow() that you can call to move focus to that component. (Note: only focusable components will actually successfully receive focus.)

1 Like

I played with this a little while ago…

If I remember correctly:

By default containers aren’t focusable. In order to give the appearance that nothing had focus, I made a container (I think it was the root container) focusable, and used requestFocusInWindow() (as Carl suggested).

Making a container focusable uses java’s setFocusable() method. Through the magic of jython, the code actually looks like this:

container.focusable = 1 container.requestFocusInWindow()