aspose file tools*
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
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

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JTextField and JButton: share the same event handler