我开始使用GWTBoostrap3,我最大的需要是创建一个包含子菜单的菜单,而这个菜单需要是动态的,所以需要用Java来做。它会像Gwt MenuBar
我的尝试……
final ListDropDown listDropDown = new ListDropDown();
AnchorButton anchorButton = new AnchorButton(ButtonType.INFO);
anchorButton.setText("btn1");
DropDownMenu dropDownMenu = new DropDownMenu();
AnchorListItem anchorListItemd = new AnchorListItem("Item 1");
dropDownMenu.add(anchorListItemd);
anchorButton.setDataToggle(Toggle.DROPDOWN);
listDropDown.add(anchorButton);
listDropDown.add(dropDownMenu);
final ListDropDown listDropDown2 = new ListDropDown();
final AnchorButton anchorButton2 = new AnchorButton(ButtonType.INFO);
anchorButton2.setText("Item 2");
DropDownMenu dropDownMenu2 = new DropDownMenu();
dropDownMenu2.setStyleName("dropdown-submenu");
dropDownMenu2.add(new AnchorListItem("Item 1"));
HTML child = new HTML();
child.addStyleName("caret");
anchorButton2.add(child);
anchorButton2.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
anchorButton2.removeStyleName("dropdown-toggle");
listDropDown.addStyleName("open");
if(!listDropDown2.getStyleName().contains("open")){
listDropDown2.addStyleName("open");
}else{
listDropDown2.removeStyleName("open");
}
}
});
listDropDown2.add(anchorButton2);
anchorButton2.removeStyleName("dropdown-toggle");
listDropDown2.add(dropDownMenu2);
dropDownMenu.add(listDropDown2);