Add a click handler to a HorizontalPanel in GWT

巧了我就是萌 提交于 2019-12-04 19:22:53

问题


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());

回答1:


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(...);


来源:https://stackoverflow.com/questions/4942140/add-a-click-handler-to-a-horizontalpanel-in-gwt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!