This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes JTextField and JButton: share the same event handler Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JTextField and JButton: share the same event handler" Watch "JTextField and JButton: share the same event handler" New topic
Author

JTextField and JButton: share the same event handler

Mousa A. Rafi
Greenhorn

Joined: Jan 30, 2005
Posts: 28
I've a JFrame that has a JTextField and a JButton object. After typing something in the Textfield I want the JButton to be clicked when I hit Enter.
How can I do it? Does it have something to do with Actions?

Code example will be helpful. Thanks in advance.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6



This is one of several ways. You could also create an Action and give both components and instance of said Action. Most of the code would look the same though.


GenRocket - Experts at Building Test Data
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
here's another way

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: JTextField and JButton: share the same event handler
 
Similar Threads
MouseListener - mouseEntered question.
Beginning GUI programming exercise. Please help to figure out why it does not compile.
How To make Button Display in JTextarea
Simple Calculator help
setFocus in JButton is there any?