GWT CellTable - 设置列宽 [英] GWT CellTable - set column width

查看:28
本文介绍了GWT CellTable - 设置列宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在GWT中设置CellTable的列宽?

Is it possible to set the column width of CellTable in GWT?

推荐答案

As of the GWT 2.2 table.setWidth and table.setColumnWidth is supported

As of GWT 2.2 table.setWidth and table.setColumnWidth are supported

table.setWidth("100%", true);
table.setColumnWidth(nameColumn, 35.0, Unit.PCT);
table.setColumnWidth(addressColumn, 65.0, Unit.PCT);

我能够使用一种以编程方式设置宽度的方法来扩展 CellTable.这有点麻烦,因为应该执行此操作的所有实际方法都是 CellTable 私有的,而且 GWT 似乎应该直接提供此方法,但它似乎有效.

I was able to extend the CellTable with a method that sets the widths programmatically. It's a bit of a hack since all the real methods that should do this are private to CellTable and it seems like GWT should provide this method directly, but it seems to work.

public void setColumnWidths(List<Integer> widths)
{
    TableElement tel = TableElement.as(getElement());
    NodeList<Element> colgroups = tel.getElementsByTagName("colgroup");
    if (colgroups.getLength() == 1)
    {
       TableColElement cge = TableColElement.as(colgroups.getItem(0));
       NodeList<Element> cols = cge.getElementsByTagName("col");
       for (int j = 0; j < widths.size(); j++)
       {
           TableColElement column = null;
           if (cols.getLength() > j)
           {
               column = TableColElement.as(cols.getItem(j));
           }
           else
           {
               column = cge.appendChild(Document.get().createColElement());
           }

           column.setWidth(widths.get(j)+"px");

       }

    }
}

这篇关于GWT CellTable - 设置列宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆