如何将点击处理程序添加到HorizontalPanel
?
它在较新的GWT版本中使用addDomHandler()
,但我不得不降级到GWT 2.0.4,这是不支持的。我曾经这样做过:
horizontalPanel.getWidget(1).addDomHandler(someClickHandler,ClickEvent.getType());
//or
horizontalPanel.addDomHandler(someClickHandler, ClickEvent.getType());
答案 0 :(得分:33)
使用FocusPanels而不是挂钩本机事件。要捕获整个面板的点击次数:
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.
或者捕捉HorizontalPanel中单元格内的点击次数:
IsWidget child; // Any widget
HorizontalPanel panel = new HorizontalPanel();
FocusPanel clickBox = new FocusPanel();
clickBox.add(child);
panel.add(clickBox);
clickBox.addClickHandler(...);