Generic reference to actual object


I’m trying to write a TextField with autoselect.

I do it in this way:

    final TextField myField = new TextField();


    myField.addFocusListener(new FocusListener() {
        public void focus(FocusEvent event) {

My question is: if I would be more generic, how could I rewrite the “myField.selectAll();”, i.e. how to write "


That’s what the event is for. It has a method for getting the source component.

You’re right.

Meantime I’ve solved in this way (just for the other looking for an answer, if any):

            ((TextField) event.getComponent()).selectAll();

Thanks for your answer pal!