将元素转换为FlowPanel?

时间:2012-12-17 21:02:04

标签: gwt

我正在尝试创建自己的复合按钮,使用div作为外部父级:

public class CompoundButton extends ButtonBase {
    public CompoundButton() {
        super(DOM.createDiv());
    }
}
但是,ButtonBase的构造函数想要一个Element实例,所以我正在使用DOM.createDiv()调用。但是现在我如何才能添加子窗口小部件?:

public CompoundButton() {
    super(DOM.createDiv());  <-- we're just a div.

    // ButtonBase has no "add()" method - but this class is really 
    // just a div instance, so shouldn't I be able to convert it to 
    // a FlowPanel for example to be able to add elements to it here?
    this.add(new FlowPanel());   <-- not possible, "add()" not available here.

由于

1 个答案:

答案 0 :(得分:0)

按钮基数占用一个单元格,而flowpanel不是一个单元格,复合按钮的代码错误,因为它不会向其父级发送单元格。

正确的代码是

public class CompoundButton<C> extends ButtonBase<C>
{
   protected CompoundButton( ButtonCellBase<C> cell )
   {
        super( cell );
   }
}