Dom 如何替换面板中的GWT小部件?

Dom 如何替换面板中的GWT小部件?,dom,gwt,Dom,Gwt,我有一个组合,它的主小部件有两个子部件,因此: public MyComposite() { child1 = new FlowPanel(); child1.getElement().setId("child1"); child2 = new FlowPanel(); child2.getElement().setId("child2"); panel = new FlowPanel(); panel.add(child1); pan

我有一个组合,它的主小部件有两个子部件,因此:

public MyComposite() {
    child1 = new FlowPanel();
    child1.getElement().setId("child1");

    child2 = new FlowPanel();
    child2.getElement().setId("child2");

    panel = new FlowPanel();
    panel.add(child1);
    panel.add(child2);
    initWidget(panel);
}
在构建MyComposite之后的一段时间,我想将child1换掉,用另一个小部件new-child1替换它

我也许可以通过调用panel.remove(child1)删除child1,然后通过调用panel.add(new-child1)添加我的新小部件;但这会导致先渲染child2,不是吗

那么,如何在不更改面板子级顺序的情况下将child1替换为new-child1?

尝试
insert()
而不是
add()

不幸的是,您无法调用
insert()
,因为它受保护,所以您需要扩展
FlowPanel

public class UsefulFlowPanel extends FlowPanel {
    public void add (int index, Widget child) {
        insert (child, getElement(), index, true);
    }
}

应该有用。

上次我看插入是一种公共方法:嗯。。。谷歌一定已经为我返回了一个旧版本的文档。在1.5中没有公开: