如何跨越GWT表列和小部件?

时间:2014-03-17 07:40:43

标签: gwt

我是GWT的新手,想要创建一个格式低的GWT表。在这里,键和值对于每个事实都是动态的。

    -------------------------
    |     | key1 | value1   |
    |     |----------------
    |Fact1| key2 | value2   |
    |     |----------------
    |     | key3 | value3   |
    |-------|----------------
    |     | key1 | value1   |
    |Fact2|----------------
    |     | key2 | value2   |
    |------------------------

我想出了下面的代码。这是正确的方法吗?任何意见都将不胜感激。

    public void onModuleLoad()
     {

        FlexTable t = new FlexTable();
        t.setText(0, 0, "FACT1");
        t.getFlexCellFormatter().setColSpan(0, 1, 3);
        FlexTable row1 = new FlexTable();
        row1.setText(0, 0, "KEY1");
        row1.setText(0, 1, "VALUE1");       
        row1.setText(1, 0, "KEY2");
        row1.setText(1, 1, "VALUE2");       
        row1.setText(2, 0, "KEY3");
        row1.setText(2, 1, "VALUE3");
        t.setWidget(0, 1, row1);

        t.setText(1, 0, "FACT2");
        t.getFlexCellFormatter().setColSpan(1, 1, 2);
        FlexTable row2 = new FlexTable();
        row2.setText(0, 0, "key1");
        row2.setText(0, 1, "value1");       
        row2.setText(1, 0, "key2");
        row2.setText(1, 1, "value2");       
        t.setWidget(1, 1, row2);
    }

}

2 个答案:

答案 0 :(得分:0)

这种方法没有问题。它按预期工作,但您创建了3个FlexTable来解决它,只能使用单个FlexTable进行解决。

注意:有关详细说明,请参阅代码本身的内联注释

<强>代码:

    FlexTable t = new FlexTable();
    t.setBorderWidth(1);
    t.setWidth("200px");
    t.setText(0, 0, "[0,0]");
    // 0th column span across 3 rows
    t.getFlexCellFormatter().setRowSpan(0, 0, 3);
    t.setText(0, 1, "[0,1]");
    t.setText(0, 2, "[0,2]");
    // do not consider that 0th column of 2nd and 3rd row are also equipped by [0,0]
    // put next element at 0th column of 2nd row
    t.setText(1, 0, "[1,0]");
    t.setText(1, 1, "[1,1]");
    t.setText(2, 0, "[2,0]");
    t.setText(2, 1, "[2,1]");

    t.setText(3, 0, "[3,0]");
    t.getFlexCellFormatter().setRowSpan(3, 0, 2);
    t.setText(3, 1, "[3,1]");
    t.setText(3, 2, "[3,2]");
    t.setText(4, 0, "[4,0]");
    t.setText(4, 1, "[4,1]");

屏幕截图与您首先输出:

enter image description here

答案 1 :(得分:0)

不,你可以这样做,

FlexTable row1 = new FlexTable();
row1.setText(0, 0, "KEY1");
row1.setText(0, 1, "VALUE1"); 
row1.setText(1, 0, "KEY2");
row1.setText(1, 1, "VALUE2");

FlexTable t2 = new FlexTable();  
t2.setText(0, 0, "Fact1");
t2.setText(0, 1, row1); 
t2.setText(1, 0, "Fact2");
t2.setText(1, 1, row2);
verticalpanel.add(t2);