This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara 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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA 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

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: JTextField and JButton: share the same event handler