0

我正在尝试创建自己的复合按钮,使用 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.

谢谢

4

1 回答 1

0

Button base 需要一个单元格,而 flowpanel 不是一个单元格,并且您的复合按钮代码是错误的,因为它没有将单元格发送到其父级。

正确的代码是

public class CompoundButton<C> extends ButtonBase<C>
{
   protected CompoundButton( ButtonCellBase<C> cell )
   {
        super( cell );
   }
}
于 2012-12-18T06:50:23.430 回答