Search code examples
gwtbuttonwidgetcomposite

GWT - extending Composite instead of Widget


Im starting to work with GWT and build my own Button. I read about best practices and that I should extend Composite instead of Widget. But why? Here on Stackoverflow i read that the GWT Widgets have special behaviour for some browsers, but when I extend a Widget that behaviour isn't lost, is it? The point is, I want a Button, just with another style. And because I need it more than once, I dont want to repeat the code all the time. But if I extend Composite I must offer the same methods like Button to hand off things like setClickHandler(...). This looks like alot of overhead.


Solution

  • Use Composite of you want to create complex widget. The Composite class allows you to use others existing widget inside your widget.

    For your case, just subclass Button widget because you don't want add complexity to your button.