Wednesday, December 29, 2010

Tip # 7: GWT Containers and SmartGWT widgets

Guys, setting width:100% in native CSS wouldn't really solve this problem. Contained components need to know the actual pixel width in order to implement various layout algorithms that go beyond CSS.

The issue here is that GWT's containers do not provide an API similar to Canvas.getInnerWidth(), which children can use to find out the available space to draw themselves in, and hence recursively lay out out their own children. Nor do they fire events when they are resized, or when the available width changes for various reasons (eg scrollbar(s) introduced, or CSS style changes add borders and hence reduce space).


A lot of parent<->child coordination and signaling is required to really create an extensible pixel-perfect layout system. SmartClient has implemented all the necessary hooks to allow a third-party widget to be embedded inside a Canvas and participate in a precise layout, but GWT is not there yet.


If you absolutely must place a SmartGWT interface inside a GWT container and you want it to fill the container, the best approach is to listen for the window-level resize event and run your own layout calculations that ultimately call resizeTo() on your topmost SmartGWT widget. All SmartGWT widgets nested under that topmost widget will then handle layout normally.

No comments:

Post a Comment