Adding custom icon to the menu I get IllegalArgumentException

Adding custom icon to the menu I get IllegalArgumentException

No enum constant com.vaadin.flow.component.icon.VaadinIcon.icons/square.png

Following https://ai-assistant.jmix.io/chatbot istruction for the query "add custom icon to menu"
and docs …

Steps
(1)
I put new icon into
src\main\resources\META-INF\resources\icons\square.png
(2)
in the menu.xml
i put the icon png reference

‘‘menu id=“square” title=“Test” icon=“icons/square.png”’’

(3) Run
after login i get
IllegalArgumentException: No enum constant com.vaadin.flow.component.icon.VaadinIcon.icons/square.png

Hello!

The menu.xml file supports only icons that can be used in com.vaadin.flow.component.icon.Icon component: VaaindIcon and LumoIcon.

For PNG icons use Image component. But in case of menu, you should write a Java code in the MainView in order to add a PNG icon:

@ViewComponent
private JmixListMenu menu;
@Autowired
private UiComponents uiComponents;

@Subscribe
public void onInit(final InitEvent event) {
    JmixImage<String> image = uiComponents.create(JmixImage.class);
    image.setSrc("icons/square.png");
    image.setClassName(LumoUtility.IconSize.SMALL);
    image.setThemeName("scale-down");
    menu.getMenuItem("square").setPrefixComponent(image);
}
1 Like

Thanks for the suggestion.
I didnt know the method this is what I was looking for
to add the icon to the menu

@ViewComponent
private JmixListMenu menu;
setPrefixComponent

I tryied your code it works very well.
Thanks