Generic reference to actual object

Hi,

I’m trying to write a TextField with autoselect.

I do it in this way:

    final TextField myField = new TextField();

[…]

    myField.addFocusListener(new FocusListener() {
        
        @Override
        public void focus(FocusEvent event) {
            myField.selectAll();
        }
    });

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

Thanks

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!