开发者

How to set border for events in GWT?

I've one Label in my custom FlowPanel which implements HasDoubleClickHandlers.

    final Label label = new Label("Click he开发者_如何学运维re to write");
    label.addClickHandler(new ClickHandler() {
        @Override
        public void onClick(ClickEvent event) {
            clicked();
        }
    });
    final CustomFlowPanel customFlowPanel=new CustomFlowPanel();
    customFlowPanel.addDoubleClickHandler(new DoubleClickHandler() {
        @Override
        public void onDoubleClick(DoubleClickEvent event) {
            if (event.getSource() instanceof FlowPanel) {
                doubleClicked();
            }
        }
    });
    custoFlowPanel.add(label);

The problem is when i double click to the label doubleClicked() should not execute. How to prevent executing doubleClicked() when label is double clicked? Thanks in advance!!!


You could just check the DoubleClickEvent if the label was clicked and if not you call doubleClicked().

customFlowPanel.addDoubleClickHandler(new DoubleClickHandler() {           
      @Override         
      public void onDoubleClick(DoubleClickEvent event) {             
          Element clicked = event.getNativeEvent();
          if (!clicked.Equals(label.getElement())
          {
              doubleClicked();         
          }
      }     
}); 


I haven't tried it yet, but try adding a double click handler on the label and use Event.stopPropagation() on it. This prevents the event from being propagated to the parent.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜