問題描述
如何更改 gwt 面板的內容? (How to change the content of a gwt panel?)
假設我有一個名為 A 的視圖,它的 xml 類似於:
<g:HTMLPanel>
<my:widgetA>
....
</my:widgetA>
</g:HTMLPanel>
另外,我還有另一個名為 widgetB 的小部件。我想根據某些條件更改視圖 A 的內容,例如:
if (...is true) {
A.clear();
A.add(widgetA);
} else {
A.clear();
A.add(widgetB);
}
現在的問題是視圖 A 無法正確顯示 widgetA。視圖 A 在添加 widgetA 時變為空白。上面的實現有什麼問題?
參考解法
方法 1:
You might be adding a widget, that implements RequiresResize or at least needs to be given a fixed size.
To find out if that is the case, just call [setSize](http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/ui/UIObject.html#setSize(java.lang.String, java.lang.String)) on that widget with a fixed size like that: widgetA.setSize('50px','50px);'
If that works, you either need to provide a size or use a panel, which implements ProvidesResize.
(by injoy、Sebastian Baumhekel)