Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT focus on a TextBox it not working

Tags:

focus

gwt

I am trying to focus on a particular list view in a tree, I am using the following code

    this.txtListName.setCursorPos(this.txtListName.getText().length());
    this.txtListName.setFocus(true);

The text view has the cursor blinking inside it but when I type a key nothing happens, I have to select the text view again before being able to type.

Why is this happening.

SOLVED

The setting the the focus was done inside a for loop that looped over and created the Tree Items, when I removed it from the for loop it worked.

like image 831
jax Avatar asked Nov 28 '10 08:11

jax


People also ask

How do I set focus in GWT?

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


1 Answers

Could it be that something in your current call stack is taking the focus away after you set it. You could try setting the focus in a timeout:

(new Timer() {
   @Override
   public void run() {
     txtListName.setFocus(true);
   }
}).schedule(0);
like image 114
Martin Algesten Avatar answered Sep 22 '22 16:09

Martin Algesten