Focus and selectAll on a TextField


I’d like to select all the text in a TextField as long as this component gets focused.

I’d trying to do it in this way:

    final TextField myField = new TextField();


    myField.setValue("Hi there!");
    myField.addFocusListener(new FocusListener() {
        public void focus(FocusEvent event) {
            // TODO Auto-generated method stub

The snipped above is generated by eclipse.
The problem is that eclipse gives me an error on the addFocusListener line saying “Multiple markers at this line
- The method addFocusListener(FieldEvents.FocusListener) in the type AbstractTextField is not applicable for the arguments (new FocusListener(){})”.


Also on the focus definition there is another error, saying “The method focus(FieldEvents.FocusEvent) of type new FocusListener(){} must override or implement a supertype method”, but the @Override is present.

What am I doing wrong?


Try to add/edit imports manually. It sometimes happens to me also and sometimes imports are managed automatically correctly.

It’s not the problem, if I look at the error.

Anyway, I’ve added a import com.vaadin.* and it doesn’t change.


Don’t use *. Add exactly:



You’re right!!!

BTW (just for the other folks reading), the correct imports are:

import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.event.FieldEvents.FocusEvent;