如何在GWT CellBrowser上设置第一列宽度

时间:2011-03-01 21:21:46

标签: gwt cellbrowser

有一个错误阻止设置CellBrowser小部件的第一列宽度。还有一个解决方法,在这里解释

http://groups.google.com/group/google-web-toolkit/browse_thread/thread/4fc39b5805833ea2

显然它可以工作,但任何人都可以解释如何将CellBrowser子类化以使其工作吗?请告诉我一些代码。

1 个答案:

答案 0 :(得分:0)

    CellBrowser cellBrowser = new CellBrowser(model, null) {

        // HACK: workaround for setDefaultColumnWidth not setting the width of the first column!
        // SEE: https://groups.google.com/forum/?pli=1#!topic/google-web-toolkit/T8Ob...

        public void setDefaultColumnWidth(int width) {
            super.setDefaultColumnWidth(width);
             SplitLayoutPanel splitPanel =  (SplitLayoutPanel) getWidget();
             splitPanel.setWidgetSize(splitPanel.getWidget(0), width);
        }
    };

    cellBrowser.setDefaultColumnWidth(300);   

如果你想要一个带有这个修复的可重用类(这可能是一个好主意),那么将这个匿名子类转换为常规子类就足够了:

    public class FixedCellBrowser<T> extends CellBrowser<T> {

        public FixedCellBrowser(TreeViewModel model, T root) {
            super(model, root);
        }

        public void setDefaultColumnWidth(int width) {
            super.setDefaultColumnWidth(width);
             SplitLayoutPanel splitPanel =  (SplitLayoutPanel) getWidget();
             splitPanel.setWidgetSize(splitPanel.getWidget(0), width);
        }
    }

(注意:我没有尝试编译此代码。)

相关问题