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());
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(...);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.