View Full Version : Widget Focus

11 Oct 2011, 4:54 AM
I see that Window.setFocusWidget(Widget) is used to receive the focus. It works perfectly fine!.

But how do I set focus to a widget which is added to the non window containers such as ContentPanel
or LayoutContainer?.

The following example does not have default focus. One has to click text field to start editing.


I tried widget.focus(), widget.el().focus() after the component is rendered. But still the focus is not working.

11 Oct 2011, 6:26 AM
You should try this in your panel class :
protected void onAttach() {


11 Oct 2011, 12:02 PM
Also put your focus calls in a deferred scheduler. Most browsers will not allow the focus to be achieved until after the event loop is finished.

Scheduler.get().scheduleDeferred( new ScheduledCommand() {
public void execute( ) {
widget.setFocus(true); // assuming GWT widget or component.focus( ); for GXT


12 Oct 2011, 12:23 AM
Jason's solution worked for me. Thanks Jason!.