I have few TextField
s on my frame. I want to know the TextField
name which is currently focused. Can someone please help me? How can I find out the current focused object name?
Thanks
I have few TextField
s on my frame. I want to know the TextField
name which is currently focused. Can someone please help me? How can I find out the current focused object name?
Thanks
Every JComponent has a hasFocus method that you can use to check if it has focus. However, this has been changed, and now you should use isFocusOwner.
So run over all the text fields in your frame, and check on each of them if it is isFocusOwner by calling that method.
You could also get the focus owner through the frame.
JFrame.getFocusOwner()
(inherited from Window.getFocusOwner()
) ought to return a reference to the component with focus. getMostRecentFocusOwner()
might also be of interest.
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.