Menus

It's time for more concrete less abstract stuff. Let's talk about menus. Menus are a way to group functionality in a very small area of the page. The first step to create a menu, is to instantiate a new MenuBar:

MenuBar menuBar = new MenuBar();

Now, we can add a hierarchy of instances of MenuItem. To add items directly to the menu bar, you can do this:

MenuItem submenu1 = menuBar.addItem("Submenu 1", null);
MenuItem submenu2 = menuBar.addItem("Submenu 2", null);

This will show the following menu:

Menus

We can add child elements to the submenus:

submenu1.addItem("Option 1", null); submenu1.addItem("Option 2", null); submenu2.addItem("Option 3", null); ...

Get Vaadin 7 UI Design By Example Beginner's Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.