如何添加点击处理程序到HorizontalPanel?
它使用了更新的GWT版本中的addDomHandler(),但是我不得不降级到不支持的GWT 2.0.4.我以前这样做:
horizontalPanel.getWidget(1).addDomHandler(someClickHandler,ClickEvent.getType()); //or horizontalPanel.addDomHandler(someClickHandler,ClickEvent.getType());
解决方法
使用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(...);