摆动焦点丢失输入验证器

发布于 2024-12-01 05:34:34 字数 731 浏览 1 评论 0原文

我有一个框架,上面有一些 JTextFields 。当用户从 JTextField 中退出时,我在 FocusTraversalPolicy 中执行自定义逻辑,它设置一些属性并基于它们来设置 FocusTraversalPolicy 决定焦点接下来应该去哪里。到目前为止,一切都很好。

但我希望这个自定义逻辑执行每次JTextField失去焦点(在InputVerifier中,因为还有其中的验证)。

现在问题又来了:如果用户用鼠标离开该字段,InputVerifier 将被触发,一切都会好起来的。但如果用户按下TABFocusTraversalPolicyInputVerifier都会被触发,并且自定义逻辑将会被触发。被处决两次,这是我不想要的。如何在 InputVerifier 中检测到 TAB 已被按下并且不执行任何操作?我想仅当鼠标离开该字段时才在 InputVerifier 中执行自定义逻辑。或者有更好的解决方案吗?

希望我的问题很清楚。

问候,佩塔尔

I have a frame with some JTextFields on it. When the user tabs out from a JTextField, I execute custom logic in the FocusTraversalPolicy, which sets some properties and based on them the FocusTraversalPolicy decides where should the focus go next. So far so good.

But I want this custom logic to execute everytime the JTextField loses focus(in an InputVerifier, because there is also validation in it).

Now the problem and the question: If the user leaves the field with the mouse the InputVerifier will be triggered and everything will be fine. But if the user presses TAB, both the FocusTraversalPolicy and the InputVerifier will be triggered and the custom logic will be executed twice, which I don't want. How can I detect in the InputVerifier that TAB was already pressed and don't execute anything? I want to execute the custom logic in the InputVerifier only when the field is left with the mouse. Or is there a better solution?

Hope my question is clear.

Regards, Petar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

A君 2024-12-08 05:34:34

如果执行自定义逻辑,我最终会从 FocusTraversalPolicy 设置一个 boolean 标志。然后在 InputVerifier 中,如果它已经被执行,我就不会再次执行它。然后我重置了标志。

I ended up setting a boolean flag from the FocusTraversalPolicy if the custom logic is executed. Then in the InputVerifier if it is already executed I don't execute it again. Then I reset the flag.

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