让我们实现用于添加/删除子小部件的接口。MyComponent
HasWidgets
外观简单如MyComponent.ui.xml
<g:FlowPanel ui:field="main" />
同时将 ind 指定的方法委托给 :HasWidgets
FlowPanel
public class MyComponent extends Composite implements HasWidgets {
private static MyComponentUiBinder uiBinder = GWT.create(MyComponentUiBinder.class);
interface MyComponentUiBinder extends UiBinder<Widget, MyComponent> {}
@UiField
FlowPanel main;
public MyComponent() {
initWidget(uiBinder.createAndBindUi(this));
}
@Override
public void add(Widget w) {
main.add(w);
}
@Override
public void clear() {
main.clear();
}
@Override
public Iterator<Widget> iterator() {
return main.iterator();
}
@Override
public boolean remove(Widget w) {
return main.remove(w);
}
}
叫
<M:MyComponent>
<g:Label text="some text" />
</M:MyComponent>
将以这种方式工作。