File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes how to identify which control get focus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "how to identify which control get focus" Watch "how to identify which control get focus" New topic
Author

how to identify which control get focus

mani senthil
Greenhorn

Joined: Jan 18, 2007
Posts: 17
suppose there are two textbox and we want to find which textbox has got foucus currently?
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
there are a number of ways

check the textfields to see if either currently has the focus
if(textField1.isFocusOwner())...
else if(textField2.isFocusOwner())...

check the focusManager to get the focused component,
Component currentFocusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();

add focusListeners, and set flags when focused
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to identify which control get focus