简体   繁体   English

默认情况下,如何知道何时对父组件可见或由用户操作启动了对第一个组件的关注

[英]How to know when the gained focus on the first component is initiated by default when parent component became visible or by users actions

I have a popup component which has a first component JTextComponent and I need to recognize in FocusListener where from the focus gained to this component: when popup appears and the component get focus by default or user clicks on it. 我有一个弹出组件,该组件具有第一个组件JTextComponent,我需要在FocusListener中识别从该组件获得的焦点所在的位置:出现弹出窗口时,默认情况下该组件获得焦点或用户单击它。 I didn't find the way to do it using FocusEvent. 我没有找到使用FocusEvent的方法。

Assuming a general use-case, what exactly is it that is tripping you? 假设有一个通用的用例,那到底是什么绊倒了您? In my view: 在我看来:

  1. Write the code you wish to execute when focus is gained in a method, say onFocusGained(boolean defaultFocus) . 编写在方法中获得焦点时希望执行的代码,例如onFocusGained(boolean defaultFocus)
  2. Call it from the FocusEvent methods with onFocusGained(true) . 使用onFocusGained(true)从FocusEvent方法调用它。
  3. Call it from the MouseAdapter methods with onFocusGained(false) . 使用onFocusGained(false)从MouseAdapter方法调用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM