2009-12-15

GWT EventDispatch and widgets width and height


When you're constructing Widget in GWT - it's size is 0 until it's rendered. It's different from Swing, Swing assumed that you're working in EventDispatcher and calculated all sizes instantly. It is not announced but looks like GWT have it's event dispatcher too, and you can use DeferredCommand class to place Command into events loop. Using this approach you can construct Widget, place it into some Container, and then add some Command to DeferredCommand to work with widget's size after current construction operation will be complete and Widget will get it's size.

It looks like problem of all young widget toolkits, like Swing itself many years ago. They are showing it, its simple, its cool. But when you start coding real application using that toolkit - you'll get many problems, many different "hidden" features and many tricks and workarounds. After many years they'll tell you about EventDispatcher, then they'll implement different kinds of BackgroundWorkers, and different rules how to "use correctly" this toolkit. You can remember situation with "EventDispatcher rule" of Swing and how it was changed from Java5 to Java6 (while nothing inside was changed). Now we can see similar situation with JavaFX, and GWT goes the same way.

No comments: