Search code examples
javavaadinmenubarcaptionvaadin8

Vaadin: Remove caption from menu item


i have a menu bar with some items.i want each item to display only it's icon.so how can i remove caption from each item? this is what i have:

MenuBar actionBar = new MenuBar();
menuBar.addItem(translator.getString("home"),VaadinIcons.HOME,(selectedItem) 
-> getUI().home());
MenuItem user= menuBar.addItem(AspirinSession.getCurrent().getCurrentUser().getDisplayName(), 
VaadinIcons.MENU, null);
menuBar.addStyleName(ValoTheme.MENUBAR_BORDERLESS);

enter image description here


Solution

  • Either do a setCaption("") on the buttons or do not add a caption in the fist place:

    menuBar.addItem("", VaadinIcons.HOME ,(selectedItem) -> getUI().home());
    MenuItem user= menuBar.addItem("", VaadinIcons.MENU, null);
    

    That should do the trick.

    You can play around with buttons on their demo page (hit the "edit" on the right). Or maybe check their CSS approach here, that would still allow you to add text to a button.