SWT:正确处理自定义控件中失去/获得的焦点

发布于 2024-09-03 19:55:33 字数 517 浏览 1 评论 0原文

我们的控制
我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遇到 2024-09-10 19:55:33

简而言之,无法确定哪个控件从 focusLost() 中获得了焦点。

我建议将 FocusListener 添加到组合中的每个控件(您可以通过迭代 getChildren() 来自动执行此操作),并使用公共字段跟踪焦点对象。

换句话说,遗憾的是没有 API 函数可以为您执行此操作。

Simply put, there is no way of determining which control has gained focus from within focusLost().

I would suggest adding FocusListeners to each control in your composite (you can automate this by iterating through getChildren()) 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文