SWT/Jface SelectionlIstener

来源:互联网 发布:手机淘宝全部宝贝设置 编辑:程序博客网 时间:2024/04/28 06:07

 SelectionListener listener = new SelectionListener(){
   public void widgetSelected(SelectionEvent e) {
    System.out.println("widgetSelected事件");
   }
   public void widgetDefaultSelected(SelectionEvent e) {
    System.out.println("widgetDefaultSelected事件");
    
   }
  };

对于selection的监听一直很好奇,为什么会有2个方法,什么控件执行什么方法?

widgetDefaultSelected

void widgetDefaultSelected(SelectionEvent e)
Sent when default selection occurs in the control.

For example, on some platforms default selection occurs in a List when the user double-clicks an item or types return in a Text. On some platforms, the event occurs when a mouse button or key is pressed. On others, it happens when the mouse or key is released. The exact key or mouse gesture that causes this event is platform specific.

Parameters:
e - an event containing information about the default selection

官方的api说的也很泛泛。我们直观的理解就是List 这个控件在双击的时候会触发widgetDefaultSelected的方法,但是同时也会触发widgetSelected这个方法,所以我觉得就没default存在的必要了。

真正的开发中真没遇到widgetDefaultSelected方法来处理业务逻辑时候,求解释??

 

以下是老外的说法:

Use widgetSelected. In fact, all the better is to simply extendSelectionAdapter and only override thewidgetSelected method and completely ignorewidgetDefaultSelected.

 

和咱的想法是一样的。