简体   繁体   English

GWT材质-设置下拉选择文本

[英]GWT Material - Set Dropdown Selection Text

It appears that a selected item in a GWT Material DropDown does not "stick" like a traditional DropDown. 似乎GWT材质下拉菜单中的选定项目不像传统的下拉菜单那样“粘”。

First question, is that intended with new Material Designs? 第一个问题,这是新材料设计的目的吗? Am I doing something wrong? 难道我做错了什么? Is there something wrong with the library I am using? 我使用的库有问题吗?

Secondly, either way, I want the selected value to take the place of the default text. 其次,无论哪种方式,我都希望所选值代替默认文本。 Is there a better way to do it than this? 有没有比这更好的方法了?

UIBinder: UIBinder:

<m:MaterialContainer ui:field="materialContainer" paddingLeft="280">
    <m:MaterialButton ui:field="areaDropDownButton" text="Area" iconType="ARROW_DROP_DOWN" iconPosition="RIGHT" textColor="white" backgroundColor="green" activates="areaDropDown"/>
    <m:MaterialDropDown ui:field="areaDropDown" activator="areaDropDown" constrainWidth="true" />  
</m:MaterialContainer>

Java: Java:

this.areaDropDown.addSelectionHandler(new SelectionHandler() 
{
    @Override
    public void onSelection(SelectionEvent event) {
        areaDropDownButton.setText(event.getSelectedItem().toString());
    }
});

GWT Material Demo: http://gwtmaterialdesign.github.io/gwt-material-demo/#!dropdown GWT材料演示: http : //gwtmaterialdesign.github.io/gwt-material-demo/#!dropdown

Could't you use a MaterialListBox ? 您不能使用MaterialListBox吗? It seems to have the requirements for your current problem only the styling might be problematic for you 似乎对您当前的问题有要求,只有样式可能对您有问题

You could also use an UiHandler: 您还可以使用UiHandler:

@UiHandler("areaDropDown")
void onDropdown(SelectionEvent event){
  areaDropDownButton.setText(event.getSelectedItem()).getText());
}

should work 应该管用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM