Reputation:
How do i add click handlers to HorizontalPanel
?
It worked with the use of addDomHandler()
in newer GWT versions, but i had to downgrade to GWT 2.0.4 where this isn't supported. I used to do it like this:
horizontalPanel.getWidget(1).addDomHandler(someClickHandler,ClickEvent.getType());
//or
horizontalPanel.addDomHandler(someClickHandler, ClickEvent.getType());
Upvotes: 12
Views: 14453
Reputation: 6025
Use FocusPanels instead of hooking native events. To catch clicks for the whole panel:
FocusPanel wrapper = new FocusPanel();
HorizontalPanel panel = new HorizontalPanel();
wrapper.add(panel);
wrapper.addClickHandler(new ClickHandler() {
@Override
public void onClick(ClickEvent event) {
// Handle the click
}
});
// Add wrapper to the parent widget that previously held panel.
Or to catch clicks inside a cell in the HorizontalPanel:
IsWidget child; // Any widget
HorizontalPanel panel = new HorizontalPanel();
FocusPanel clickBox = new FocusPanel();
clickBox.add(child);
panel.add(clickBox);
clickBox.addClickHandler(...);
Upvotes: 34