How to change Button icon and text by dynamically?

My code not working:

Button btnSearch = new Button("Apply filter");
btnSearch.setIcon(FontAwesome.SEARCH);
btnSearch.addClickListener(e->{
e.getButton().setIcon(FontAwersome.CANCEL)
e.getButton().setCaption("Cancel filter");
});

This should work. Please see that you are not doing something else in the rest of the code that is affecting this.

Роман Последовский:
My code not working:

Button btnSearch = new Button("Apply filter");
btnSearch.setIcon(FontAwesome.SEARCH);
btnSearch.addClickListener(e->{
e.getButton().setIcon(FontAwersome.CANCEL)
e.getButton().setCaption("Cancel filter");
});

Maybe it’s simple misspelled? :slight_smile:

Try e.getButton().setIcon(FontAwesome.CANCEL)instead.