Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I replace a GWT widget in a Panel?

Tags:

dom

gwt

I have a Composite whose main widget has two children, thus:

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);
}

Some time after construction of MyComposite, I want to swap child1 out, replacing it with another widget, new-child1.

I could perhaps remove child1 by calling panel.remove(child1), and then add my new widget by calling panel.add(new-child1); but this would cause child2 to be rendered first, wouldn't it?

So, how can I replace child1 with new-child1 without changing the order of panel's children?

like image 375
David Avatar asked Oct 02 '09 07:10

David


People also ask

What is widget in GWT?

Widgets allow you to interact with the user. Panels control the placement of user interface elements on the page. Widgets and panels work the same way on all browsers; by using them, you eliminate the need to write specialized code for each browser.

What is horizontal panel in GWT?

A panel that lays all of its widgets out in a single horizontal column.

Which of the following panel represents a panel that contains HTML and which can attach child widgets to identified elements within that HTML?

This widget represents a panel that contains HTML, and which can attach child widgets to identified elements within that HTML.


1 Answers

Try insert() instead of add().

Unfortunately, you can't call insert() since it's protected, so you need to extend FlowPanel:

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

should work.

like image 68
Aaron Digulla Avatar answered Oct 27 '22 16:10

Aaron Digulla