14 Nov 2011 7:09 AM #1
[CLOSED] Unable to add more than one widget to a ContentPanel?
Feature or bug?
Here's a very simple example code:
ContentPanel view = new ContentPanel(); TextButton btn1 = new TextButton("1"); TextButton btn2 = new TextButton("2"); view.add(btn1); view.add(btn2); System.out.println("view.getWidgetCount() = " + view.getWidgetCount()); // = 1 RootLayoutPanel.get().add(view);
If it's a feature (like "you have to add another panel wrapping all buttons") - what would be getWidgetCount() for?
14 Nov 2011 7:28 AM #2
ContentPanel is a SimpleContainer and so only contains one child at a time. You need to wrap them in a VerticalLayoutContainer for example
15 Nov 2011 4:15 AM #3
Thank you, I didn't notice the new SimpleContainer concept. I guess, it should be fixed/improved though, since the SimpleContainer.add() method says:
The expectation is that this method would be overridden by a child object.
Also, as mentioned, inherited methods like "getWidgetCount()" or "getWidget(int)" lead to even more confusion. Seeing this method on a SimpleContainer make a developer assume, it could actually contain more than one widget. Making those methods private, for example, would prevent such assumptions.
15 Nov 2011 4:29 AM #4
Theses methods are comming from a GWT interface.
In GXT 3 the layouts are bound into the containers. We are still working on adding more javadocs, however there are currently no plans to change the design. Contentpanel does not have any insert method. SimplePanel from GWT behaves also exactly the same way, only that it will throw an exception.
If you take a look at Widget.removeFromParent you will see that the HasWidget interface (that has the add method) is required).
If you require to handle more than one widget, you need to add another container into the ContentPanel, like a FlowLayoutContainer.
In GXT 2 the add method maybe always works. However when using a FitLayout only the first child would have been used, same in a CenterLayout. In GXT 3, the container takes care of all this.