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 Listening for enterkey with any component in focus Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Listening for enterkey with any component in focus" Watch "Listening for enterkey with any component in focus" New topic
Author

Listening for enterkey with any component in focus

Gulshan Singh
Ranch Hand

Joined: Apr 22, 2009
Posts: 41
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

Joined: Jun 13, 2009
Posts: 2091
    
    7
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:



 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Listening for enterkey with any component in focus
 
Similar Threads
adding keyevents to scrollbars
how to give focus to a component ?
LIKE a screensaver??????
Focus Traversal Policy Question
JTextField Action on Tab key