了解swt SelectionListener中的widgetSelected事件和widgetDefaultSelected事件?

Understanding the widgetSelected event and the widgetDefaultSelected event in the swt SelectionListener?

我无法理解 SWT SelectionListener 中两种方法之间的区别。 javadoc如下:

void org.eclipse.swt.events.SelectionListener.widgetSelected(SelectionEvent e)

Sent when selection occurs in the control.

For example, selection occurs in a List when the user selects an item or items with the keyboard or mouse. 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.

void org.eclipse.swt.events.SelectionListener.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.

在我看来,当用户以任何方式选择一个小部件时,widgetSelected() 就会被调用。 widgetDefaultSelected() 在用户 完成 与小部件交互时调用。对于文本小部件,将按 Enter 键;对于列表,这将是双击列表项;对于日期,将按 Enter。

这个理解对吗?

您的一般理解是正确的,尽管术语 'finished' 可能并非在所有情况下都 100% 准确。

发送(默认)选择事件的小部件在 JavaDoc 中记录了它们各自 addSelectionListener 方法的特定细节。在那里您可以阅读是否以及何时发送 widgetSelected and/or widgetDefaultSelected

例如,如果您查看 Link::addSelectionListener JavaDoc,您会发现 widgetDefaultSelected() 从未被调用。