java 向 GWT 中的 Horizo​​ntalPanel 添加点击处理程序

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4942140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 08:43:07  来源:igfitidea点击:

Add a click handler to a HorizontalPanel in GWT

javaeventsgwtonclick

提问by Jason Terk

How do i add click handlers to HorizontalPanel?

我如何将点击处理程序添加到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:

addDomHandler()在较新的 GWT 版本中使用,但我不得不降级到 GWT 2.0.4,因为它不受支持。我以前是这样做的:

horizontalPanel.getWidget(1).addDomHandler(someClickHandler,ClickEvent.getType());
//or
horizontalPanel.addDomHandler(someClickHandler, ClickEvent.getType());

回答by Jason Terk

Use FocusPanels instead of hooking native events. To catch clicks for the whole panel:

使用 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.

Or to catch clicks inside a cell in the HorizontalPanel:

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

IsWidget child; // Any widget
HorizontalPanel panel = new HorizontalPanel();
FocusPanel clickBox = new FocusPanel();

clickBox.add(child);
panel.add(clickBox);

clickBox.addClickHandler(...);