开发者

GWT - FlexTable - cannot see added row

I am writing a test to see how event handlers should work but it seems I am doing something wrong here because I cannot see the added Widget to the flextable :(

Here is my code snippet

Composite A:

B b=new B();
Button addItemButton = new Butt开发者_运维技巧on("+");
        addItemButton.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                Window.alert("Hello world!");
                b.addItem(itemTable);
            }

        });

Composite B:

public void addItem(FlexTable itemTable)
    {



        itemTable.add(new C());
    }

Composite C:

...

Button removeRow=new Button();
removeButton.addClickHandler(new ClickHandler() {
                public void onClick(ClickEvent event) {

                    itemTable.removeRow(?);
                }

            });

I mean nothing adds to the itemTable when I run it as GWT app in my default Internet Browser. How to refresh ItemTable or something to see its added or removed rows?

Any useful comments are appreciated


You need to look more closely at the GWT Stocks example. This is the code section which actually adds the row:

 // Add the stock to the table.
    int row = stocksFlexTable.getRowCount();
    stocks.add(symbol);
    stocksFlexTable.setText(row, 0, symbol);

The call to stocksFlexTable.setText() is what creates the row in the table and sets the text. So your code for B and C should look more like this:

//In Composite B
public void addItem(FlexTable itemTable) {  
  int row = itemTable.getRowCount();
  itemTable.setText(row, 0, symbol);
  itemTable.add(new C(row));
}

//In Composite C, the constructor saves the int argument as the field 'row'
Button removeRow=new Button();
removeButton.addClickHandler(new ClickHandler() {
  public void onClick(ClickEvent event) {
    itemTable.removeRow(C.this.row);
  }
});

If you just want to stack a bunch of widgets on top of each other (so if you don't create more than one column in the table), you should just use the VerticalPanel. It's add() method will do what you were expecting.


You need to obtain and use the current row count at runtime

itemTable.setWidget(itemTable.getRowCount(),0,new Label("Hello world"));


try using setWidget method.

public void addItem(FlexTable itemTable)
{
        itemTable.setWidget(0,0,new Label("Hello world"));
}

setWidgets requieres the arguments (row,col,Widget).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜