gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 06:08:49 25 4
gpt4 key购买 nike

我无法理解 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 键。

这种理解正确吗?

最佳答案

您的总体理解是正确的,尽管“完成”一词可能并非在所有情况下 100% 准确。

发送(默认)选择事件的小部件在其各自的 addSelectionListener 方法的 JavaDoc 中记录了特定的详细信息。您可以在此处查看 widgetSelected 和/或 widgetDefaultSelected 是否以及何时发送。

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

关于java - 了解 swt SelectionListener 中的 widgetSelected 事件和 widgetDefaultSelected 事件吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28986992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com