1

我尝试使用 GWT 创建一个 SuggestBox,到目前为止一切正常。但是我想让 SuggestBox 的弹出窗口与输入字段的大小相同,但我还没有找到一种方法来做到这一点。

如果你能给我小费,我会很高兴的。

问候凯文

4

2 回答 2

8

创建自定义类扩展DefaultSuggestonDisplay和覆盖showSuggestions方法

import java.util.Collection;

import com.google.gwt.dom.client.Style.Unit;
import com.google.gwt.user.client.ui.SuggestBox;
import com.google.gwt.user.client.ui.SuggestBox.DefaultSuggestionDisplay;
import com.google.gwt.user.client.ui.SuggestBox.SuggestionCallback;
import com.google.gwt.user.client.ui.SuggestOracle.Suggestion;

public class CustomSuggestionDisplay extends DefaultSuggestionDisplay
{
    @Override
    protected void showSuggestions( SuggestBox suggestBox, Collection< ? extends Suggestion> suggestions, boolean isDisplayStringHTML, boolean isAutoSelectEnabled, SuggestionCallback callback )
    {
        super.showSuggestions( suggestBox, suggestions, isDisplayStringHTML, isAutoSelectEnabled, callback );
        getPopupPanel().setWidth( ( suggestBox.getElement().getAbsoluteRight() - suggestBox.getAbsoluteLeft() ) + Unit.PX.getType() );
    }
}

使用以下建议框构造函数

SuggestBox suggestBox = new SuggestBox( new MultiWordSuggestOracle(), new TextBox(), new CustomSuggestionDisplay() );
于 2014-01-27T05:13:54.430 回答
0

如果您的 SuggestBox 具有固定宽度,比如说 200px,您可以应用以下样式

.gwt-SuggestBoxPopup .item{ width:  198px;}
于 2014-01-27T01:20:56.080 回答