【发布时间】:2015-12-02 09:24:33
【问题描述】:
我正在尝试为 Spring 应用程序添加导航栏(就像引导程序一样),但没有让导航菜单出现在网页上!
谁能告诉我这里出了什么问题?
下面是我的代码:
private Panel viewContainer;
private HorizontalLayout navbar;
private Button btnHome;
private Button btnNested;
private Button createNavigationButton(String caption, final String viewName) {
Button button = new Button(caption);
button.addStyleName(ValoTheme.BUTTON_SMALL);
// If you didn't choose Java 8 when creating the project, convert this
// to an anonymous listener class
button.addClickListener(event -> getUI().getNavigator().navigateTo(
viewName));
return button;
}
@Override
protected void init(VaadinRequest request) {
final VerticalLayout root = new VerticalLayout();
root.setSizeFull();
navbar = new HorizontalLayout();
navbar.setWidth("100%");
navbar.setDefaultComponentAlignment(Alignment.MIDDLE_RIGHT);
root.addComponent(navbar);
final Label brand = new Label("Nested demo");
brand.addStyleName(ValoTheme.LABEL_H1);
brand.addStyleName(ValoTheme.LABEL_NO_MARGIN);
navbar.addComponent(brand);
navbar.setComponentAlignment(brand, Alignment.MIDDLE_LEFT);
navbar.setExpandRatio(brand, 1);
btnHome = new Button("Home", FontAwesome.HOME);
btnHome.addStyleName(ValoTheme.BUTTON_BORDERLESS);
navbar.addComponent(btnHome);
btnNested = new Button("nested", FontAwesome.COFFEE);
btnNested.addStyleName(ValoTheme.BUTTON_BORDERLESS);
navbar.addComponent(btnNested);
viewContainer = new Panel();
viewContainer.setSizeFull();
root.addComponent(viewContainer);
root.setExpandRatio(viewContainer, 1);
}
非常感谢任何提示。
谢谢
【问题讨论】:
-
是 only 缺少导航栏吗?是否有任何提示(例如,您的浏览器的开发工具告诉您什么)?
-
似乎 setContent(root); init 方法中缺少调用。