How to find out which object currently has focus

前端 未结 9 814
囚心锁ツ
囚心锁ツ 2020-12-03 13:38

I have a few TextFields in my Frame. I want to know which TextField currently has focus. How can I find this information?

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 14:03

    getFocusOwner() will return the child component which is currently focused.

    But you have to check to see if it is a JTextField. Other components like buttons might be focused if they exist in your frame as well.

提交回复
热议问题