【发布时间】:2017-06-01 11:39:49
【问题描述】:
我正在使用 vaadin,我需要从菜单栏中选择的值并显示在标签中。我尝试了下面提到的一个示例代码。
final MenuBar menubar = new MenuBar();
layout.addComponent(menubar);
MenuBar.MenuItem beverages = menubar.addItem("Beverages", null, null);
Label selection = new Label("-");
layout.addComponent(selection);
MenuBar.Command mycommand = new MenuBar.Command() {
public void menuSelected(MenuItem selectedItem) {
selection.setValue("Ordered a " + selectedItem.getText() +
" from menu.");
}
};
MenuBar.MenuItem hot_beverages = beverages.addItem("Hot", null, null);
hot_beverages.addItem("Tea", null, mycommand);
hot_beverages.addItem("Coffee", null, mycommand);
MenuBar.MenuItem cold_beverages =
beverages.addItem("Cold", null, null);
cold_beverages.addItem("Milk", null, mycommand);
MenuBar.MenuItem snacks = menubar.addItem("Snacks", null, null);
snacks.addItem("Weisswurst", null, mycommand);
snacks.addItem("Salami", null, mycommand);
MenuBar.MenuItem services = menubar.addItem("Services", null, null);
services.addItem("Car Service", null, mycommand);
setContent(layout);
问题是,它只显示一个选定的项目。
如果我选择另一个项目,标签值将替换为最近选择的项目。我的要求是显示所有被选中的菜单项。
【问题讨论】:
-
请帮帮我。
-
Vaadin MenuBar 似乎不支持多选。尝试使用列表选择小部件:demo.vaadin.com/sampler/#ui/data-input/multiple-value/…
-
感谢您的回复。是的,多个值与列表一起使用。但是我需要在MenuBar,有什么办法吗?
-
@petey fyi,不知道你是否曾经这样使用过它们,但有点类似于多选列表,some menu items can be checkable。请参阅下面的答案以获取示例。干杯
标签: vaadin