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?
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.
A panel that lays all of its widgets out in a single horizontal column.
This widget represents a panel that contains HTML, and which can attach child widgets to identified elements within that HTML.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With