在GWT中向HorizontalPanel添加点击处理程序 [英] Add a click handler to a HorizontalPanel in GWT
本文介绍了在GWT中向HorizontalPanel添加点击处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将点击处理程序添加到 HorizontalPanel
?
How do i add click handlers to HorizontalPanel
?
它与使用 addDomHandler()
在较新的GWT版本中,但我不得不降级到GWT 2.0.4,这不受支持。我以前这样做:
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());
推荐答案
使用FocusPanels而不是挂起本机事件。捕获整个面板的点击:
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.
或者捕获HorizontalPanel中单元格内的点击:
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(...);
这篇关于在GWT中向HorizontalPanel添加点击处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文