摆动焦点丢失输入验证器
我有一个框架,上面有一些 JTextFields
。当用户从 JTextField
中退出时,我在 FocusTraversalPolicy
中执行自定义逻辑,它设置一些属性并基于它们来设置 FocusTraversalPolicy
决定焦点接下来应该去哪里。到目前为止,一切都很好。
但我希望这个自定义逻辑执行每次JTextField
失去焦点(在InputVerifier
中,因为还有其中的验证)。
现在问题又来了:如果用户用鼠标离开该字段,InputVerifier
将被触发,一切都会好起来的。但如果用户按下TAB
,FocusTraversalPolicy
和InputVerifier
都会被触发,并且自定义逻辑将会被触发。被处决两次,这是我不想要的。如何在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果执行自定义逻辑,我最终会从
FocusTraversalPolicy
设置一个boolean
标志。然后在InputVerifier
中,如果它已经被执行,我就不会再次执行它。然后我重置了标志。I ended up setting a
boolean
flag from theFocusTraversalPolicy
if the custom logic is executed. Then in theInputVerifier
if it is already executed I don't execute it again. Then I reset the flag.