SWT:正确处理自定义控件中失去/获得的焦点
我们的控制
我有一个 Combobox/DropDownList 的自定义 SWT 实现。
这是作为包含文本和按钮的复合体实现的。
显示列表时,我们使用一个列表控件,该控件放置在所有内容的顶部并位于文本和按钮处。
这按预期工作。
问题
但我们在 focusLost 和 focusGained 方面遇到了问题。
最终,我希望任何外部组件在自定义的任何部分获得焦点时获得 focusGained,并且仅在任何部分失去焦点<时抛出 focusLost em>并且没有其他部分获得焦点。
当焦点仅从文本移动到自定义控件内的按钮时,我想避免处理 focusLost 和 focusGained 。
有谁知道有一个 API 可以知道在焦点丢失期间焦点将落在哪里?
有谁知道如何以任何方式实现这一点?
Our Control
I have a Custom SWT implementation of a Combobox/DropDownList.
This is implemented as a Composite containing a Text and a Button.
When the list is showed, we use a List control that is placed on top of everything and positioned at the Text and Button.
This works as expected.
The Problem
But we are having issues with focusLost and focusGained.
Ultimately i would like for any external component to get a focusGained when any part of the custom gains focus and only throw a focusLost when focus is lost from any part and no other part gains focus.
I would like to avoid handling focusLost and focusGained when focus is merely moved from the text to the button inside my custom control.
Do anyone know of an API to know, during focusLost, where focus will land?
Do anyone have an idea how to implement this in any way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
简而言之,无法确定哪个控件从
focusLost()
中获得了焦点。我建议将
FocusListener
添加到组合中的每个控件(您可以通过迭代getChildren()
来自动执行此操作),并使用公共字段跟踪焦点对象。换句话说,遗憾的是没有 API 函数可以为您执行此操作。
Simply put, there is no way of determining which control has gained focus from within
focusLost()
.I would suggest adding
FocusListener
s to each control in your composite (you can automate this by iterating throughgetChildren()
) and keep track of the focus object using a common field.In other words, there is unfortunately no API function that does this for you.