Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to identify which control get focus

 
mani senthil
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
suppose there are two textbox and we want to find which textbox has got foucus currently?
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic