我在我的应用程序中使用menuBar组件,并且我想在菜单中添加一个“迷你”表单。在"contact“菜单中,用户可以在TextField中填入电话号码,然后单击submit按钮进行呼叫。我的问题是,当我选择TextField时,菜单会自动关闭。你知道有没有可能做到这一点,我该怎么做?谢谢。
这是我的菜单的一个例子
public class HeaderView extends MenuBar implements RouterLayout {
private final MenuItem tools;
private final MenuItem contacts;
public HeaderView() {
// logo
final Image img = new Image("img/logo.png", "image");
img.setHeight("44px");
this.addItem(img);
// TOOLS
tools = this.addItem("Tools");
tools.addComponentAsFirst(new Icon(VaadinIcon.TOOLS));
// CONTACTS
contacts = this.addItem("Contacts");
contacts.addComponentAsFirst(new Icon(VaadinIcon.PHONE));
// layout for the form contact
final FormLayout nameLayout = new FormLayout();
final TextField phoneField = new TextField();
phoneField.setLabel("Phone");
phoneField.setPlaceholder("Phone");
final Button sendButton = new Button("send");
// add textfield and button to the layout
nameLayout.add(phoneField, sendButton);
// add the form to the menubar
contacts.getSubMenu().addItem(nameLayout);
}发布于 2021-08-31 14:11:59
您可以尝试将contacts.getSubMenu().addItem(nameLayout)更改为contacts.getSubMenu().add(nameLayout)我不确定您是否可以在提交后自动触发子菜单的关闭。如果需要的话。
https://stackoverflow.com/questions/68925666
复制相似问题