如何将GWT表列和小部件扩展到该列中?

如何将GWT表列和小部件扩展到该列中?,gwt,Gwt,我是GWT新手,希望创建以下格式的GWT表。在这种情况下,每个事实的键和值都是动态的 ------------------------- | | key1 | value1 | | |---------------- |Fact1| key2 | value2 | | |---------------- | | key3 | value3 | |-------|----------------

我是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);
    }

}这种方法没有问题。它按预期工作,但您已经创建了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]");
首先输出的屏幕截图:

    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]");

不,你可以这样做

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);

非常感谢Braj。它解决了我的问题。这正是我想要的。非常感谢你的回复。看来Braj的答案似乎更为理想。