Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to focus on element in GWT?

Tags:

java

gwt

i have this class for my input textbox:

    class InputTextBox extends FlowPanel { 
      public InputTextBox(String labelText) { 
        super(); 
        Label label = new Label(labelText); 
        TextBox input = new TextBox(); 
        this.add(label); 
        this.add(input); 
        this.addStyleName("myBox"); 
      }


    }

How do I set focus on that textbox so when onmoduleload is called the cursor appears in the textbox? Adding a member function seems to throw many errors.

      public void setFocus(boolean b) {
        this.setFocus(b);

      } 
like image 518
Angus Beefsteak Avatar asked Jun 11 '12 00:06

Angus Beefsteak


2 Answers

You should add this block to constructor or onLoad method:

Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
@Override
public void execute() {
    //call setFocus method here:
    input.setFocus(true);
}});
like image 115
Hadi Momenzadeh Avatar answered Nov 05 '22 01:11

Hadi Momenzadeh


Make a property field for you TextBox and in your setFocus method call textBox.setFocus(true), or whatever you called your TextBox property.

like image 2
Wesley Vrancken Avatar answered Nov 05 '22 02:11

Wesley Vrancken