How to display sub-menu items of menu item and change style of this menu it

I have one menu item in menu bar. This menu item has other menu items (sub-menu items). I need that when user clicks on this menu item, sub-menu items will be displayed and to main menu item will be added some style. I tried:

MenuBar menuBar = new MenuBar();
MenuItem menuItem = menuBar.addItem(“”, null);
MenuItem item1 = menuItem.addItem(“Item 1”, null);
MenuItem item2 = menuItem.addItem(“Item 2”, null);
MenuItem item3 = menuItem.addItem(“Item 3”, null);

Command cmd = new Command() {

public void menuSelected(MenuItem selectedItem) {

[/code]When I click on menu item the style is changing, but sub-menu items are not displayed. When I remove command, sub-menu items are displayed. How can I reach both displaying sub-menu items as well as adding style name?
I’m using Vaadin 6.

Have you tried addStyleName instead of setStyleName, I assume you want to just add some accent for selected menu. I suspect when you use setStyleName, you remove some important style regarding your theme, and hence sub-menu not showing.

Method addStyleName doesn’t exist in MenuBar.MenuItem. :frowning:

Which Vaadn 6 version you have? I just checked our API archive, and according to it should be.

I’m using Vaadin 6.8.17 but my menu item is from class com.vaadin.ui.MenuBar not from com.vaadin.terminal.gwt.client.ui.

You are correct. This issue has popped up also before. I think this one is worth of trying, So instead of adding stylename, use the stylename in your theme css that is set by Vaadin 6 automatically.