Gwt 如何以编程方式打开引导下拉列表?
我开发了GWT应用程序。我还使用Twitter引导库和GWTQuery。这里有Gwt 如何以编程方式打开引导下拉列表?,gwt,twitter-bootstrap,Gwt,Twitter Bootstrap,我开发了GWT应用程序。我还使用Twitter引导库和GWTQuery。这里有下拉按钮。我想以编程方式打开它 ui.xml,如下所示: <ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder' xmlns:b="urn:import:com.github.gwtbootstrap.client.ui" xmlns:g='urn:import:com.google.gwt.user.cli
下拉按钮
。我想以编程方式打开它
ui.xml,如下所示:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:g='urn:import:com.google.gwt.user.client.ui'
...
<b:DropdownButton text="Test" ui:field="dropdownButton">
<g:FlowPanel ui:field="contentPanel"/>
</b:DropdownButton>
您可以尝试子类化DropDownButton,为触发器按钮(在类的末尾)添加一个getter,如下所示:
public class CustomDropdownButton extends DropdownBase {
private Button trigger;
/**
* Creates a DropdownButton without a caption.
*/
public CustomDropdownButton() {
super("div");
addStyleName("btn-group");
}
/**
* Creates a DropdownButton with the given caption.
*
* @param caption
* the button's caption
*/
public CustomDropdownButton(String caption) {
this();
setText(caption);
}
/**
* {@inheritDoc}
*/
@Override
protected IconAnchor createTrigger() {
trigger = new Button();
trigger.setCaret(true);
return trigger;
}
/**
* Sets the button's size.
*
* @param size
* the button's size
*/
public void setSize(ButtonSize size) {
trigger.setSize(size);
}
/**
* Sets the button's type.
*
* @param type
* the button's type
*/
public void setType(ButtonType type) {
trigger.setType(type);
}
/**
* Sets the button's icon.
*
* @param type
* the icon's type
*/
@Override
public void setIcon(IconType type) {
setBaseIcon(type);
}
/**
* {@inheritDoc}
*/
@Override
public void setBaseIcon(BaseIconType type) {
trigger.setBaseIcon(type);
}
@Override
public HandlerRegistration addClickHandler(ClickHandler handler) {
return trigger.addClickHandler(handler);
}
/**
* {@inheritDoc}
*/
@Override
public void setIconSize(IconSize size) {
trigger.setIconSize(size);
}
/**
* {@inheritDoc}
*/
@Override
public void setCustomIconStyle(String customIconStyle) {
trigger.setCustomIconStyle(customIconStyle);
}
/**
* {@inheritDoc}
*/
@Override
public void setIconPosition(IconPosition position) {
trigger.setIconPosition(position);
}
public Button getButton(){
return trigger;
}
}
现在,您的uiBinder xml中将包含:
<ui:UiBinder xmlns:ui='urn:ui:com.google.gwt.uibinder'
xmlns:b="urn:import:com.github.gwtbootstrap.client.ui"
xmlns:g='urn:import:com.google.gwt.user.client.ui'
xmlns:c='urn:import:com.example.packageWithCustomDropDown'
...
<c:CustomDropdownButton text="Test" ui:field="dropdownButton">
<g:FlowPanel ui:field="contentPanel"/>
</b:CustomDropdownButton>