How to display sub-menu items via code

I have menu bar with menu items and these menu items have sub-menu items. I need to achieve when user clicks on some other button, a specific sub-menu items will be displayed. Is it possible to “unwrap” sub-menu items via code? I’m using Vaadin 6.