When calling setText on a button with an icon as prefix, the icon is removed from the prefix slot which can cause aligment problems between the image and the label.
Button btnWithIconSlotted=new Button("Button On SlotPrefix");
Icon icon = new Icon(VaadinIcon.BULLSEYE);
icon.getElement().setAttribute("slot","prefix");
btnWithIconSlotted.setIcon(icon);
Button button = new Button("change Text of Slotted", event -> btnWithIconSlotted.setText("Button No More On SlotPrefix"));
add(btnWithIconSlotted, button);
When calling setText on a button with an icon as prefix, the icon is removed from the prefix slot which can cause aligment problems between the image and the label.
Code pointer : GeneratedVaadinButton.class protected void removeAll() { getElement().getChildren() .forEach(child -> child.removeAttribute("slot")); getElement().removeAllChildren(); }
Code Sample :
Button btnWithIconSlotted=new Button("Button On SlotPrefix"); Icon icon = new Icon(VaadinIcon.BULLSEYE); icon.getElement().setAttribute("slot","prefix"); btnWithIconSlotted.setIcon(icon);