Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Listening for enterkey with any component in focus

 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need my program to listen for an enter keypress at a certain point, but I want it to listen for it regardless of what component is in focus. I know how to do this for a certain component, like component.addKeyListener(this), but that only captures the keypress when that component is in focus. I need the program to capture it regardless of which component is in focus.
 
Rob Camick
Ranch Hand
Posts: 2580
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Generally, this is done by specify a default button for the form. Then when Enter is pressed the ActionListener association with that button will be executed. You assign the defult button using:



 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic