将点击处理程序添加到 GWT 中的 Horizo​​ntalPanel [英] Add a click handler to a HorizontalPanel in GWT

查看:41
本文介绍了将点击处理程序添加到 GWT 中的 Horizo​​ntalPanel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将点击处理程序添加到 Horizo​​ntalPanel?

How do i add click handlers to HorizontalPanel?

它可以在较新的 GWT 版本中使用 addDomHandler(),但我不得不降级到不支持此功能的 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.

或者在 Horizo​​ntalPanel 的单元格内捕捉点击:

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 中的 Horizo​​ntalPanel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆