gwt - 如何使用最大高度和溢出-y : scroll? 自动滚动 GWT SuggestBox

标签 gwt widget scroll

如何自动滚动 GWT SuggestBoxPopupPanel 上设置最大高度持SuggestBox ?目前,当用户按下键盘向上键和向下键时,建议项目的样式会发生变化,然后按 Enter 将选择列表中当前选定的项目。

当项目位于低于最大高度时,滚动条不会滚动。
我尝试扩展 SuggestBox和内部类(Class)DefaultSuggestionDisplay覆盖 moveSelectionDown()moveSelectionUp()显式调用 popup.setScrollTop() .

为了做到这一点,我需要访问当前选择的 MenuItem 的绝对顶部。因此需要访问 SuggestionMenu这也是 SuggestBox 的内部类,它是私有(private)的,并在 DefaultSuggestionDisplay 中声明为私有(private)成员没有 setter/getter 。由于 GWT 是一个 JavaScript,我们不能使用反射来访问它......有没有人有这个问题的解决方法?

谢谢。

最佳答案

我一直在四处寻找,找不到合适的解决方案(除了重新实现 SuggestBox)。以下避免了重新实现 SuggestBox:

private static class ScrollableDefaultSuggestionDisplay extends SuggestBox.DefaultSuggestionDisplay {

    private Widget suggestionMenu;

    @Override
    protected Widget decorateSuggestionList(Widget suggestionList) {
        suggestionMenu = suggestionList;

        return suggestionList;
    }

    @Override
    protected void moveSelectionDown() {
         super.moveSelectionDown();
         scrollSelectedItemIntoView();
    }

    @Override
    protected void moveSelectionUp() {
         super.moveSelectionUp();
         scrollSelectedItemIntoView();
    }

    private void scrollSelectedItemIntoView() {
        //                                     DIV          TABLE       TBODY       TR's
        NodeList<Node> trList = suggestionMenu.getElement().getChild(1).getChild(0).getChildNodes();
        for (int trIndex = 0; trIndex < trList.getLength(); ++trIndex) {
            Element trElement = (Element)trList.getItem(trIndex);
            if (((Element)trElement.getChild(0)).getClassName().contains("selected")) {
                trElement.scrollIntoView();

                break;
        }
    }
}

}

关于gwt - 如何使用最大高度和溢出-y : scroll? 自动滚动 GWT SuggestBox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8206982/

相关文章:

mysql - 用于持久保存 Google App Engine 上的 GWT 项目的外部 MySQL 数据库

java - GWT 验证的用户 session

C 的跨平台高级小部件工具包

javascript - 简单的小部件 JavaScript 库

javascript - 滚动一些 div 并同时滚动 body

css - 溢出-x和溢出之间的区别

css - Gxt 组合框选择箭头在 Firefox 和 Safari 中未正确对齐

html - 表示 UI 小部件的语义 HTML 元素

css - 在 Mobile Safari 中停止 body 滚动

gwt - 奇怪的 GWT 编译错误