Time for action – adding menu options
Follow these steps to add the buttons that will form the main menu of the application:
Add the following method to
MainLayout
:public class MainLayout extends VerticalLayout { ... public void addMenuOption(String caption, final Component component) { Button button = new Button(caption); menuLayout.addComponent(button); button.addClickListener(new ClickListener() { public void buttonClick(ClickEvent event) { contentLayout.removeAllComponents(); contentLayout.addComponent(component); } }); } }
Comment out the line that set
menuLayout
to be full size:public MainLayout() { ... //menuLayout.setSizeFull(); you can delete this line ;) ... }
Change your
LayoutFrameworkUI
class to the following:public class LayoutFrameworkUI extends UI { protected void init(VaadinRequest request) { MainLayout layout = new MainLayout(); layout.addMenuOption("Option 1", new Label("Component 1")); layout...