It seems that Panel doesn't inherit from HasClickHandlers and I can't add a clickHandler to DivElement. Is there any way to add the clickHandler to a DIV?
EDIT: The reason I can't use Label as that the DIV I want to be clickable contains other DIV.
It seems that Panel doesn't inherit from HasClickHandlers and I can't add a clickHandler to DivElement. Is there any way to add the clickHandler to a DIV?
EDIT: The reason I can't use Label as that the DIV I want to be clickable contains other DIV.
That should be all you need.
addDomHandler
will take care of "sinking" the event type for you.Use the
FocusPanel
.By default, Panel doesnt 'sink' the onCLick event. That is, clicking on Panels doesnt actually result into a 'ClickEvent' and hence the handler isnt fired. To use click events with Panel (or for that matter any other Widget) you must first invoke sinkEvents() on it with the appropriate event bits.
For example:
The above piece of code first 'enables' click events for the SimplePanel using
p.sinkEvents(Event.ONCLICK);
and then goes on to add the standard ClickHandler onto it. Note that even though SimplePanel doesnt implement HasClickHandlers, you can always add a handler using theaddHandler()
method.