aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Press ENTER and ignit activate the button Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Press ENTER and ignit activate the button" Watch "Press ENTER and ignit activate the button" New topic
Author

Press ENTER and ignit activate the button

Peter Primrose
Ranch Hand

Joined: Sep 10, 2004
Posts: 755
Hi all,

Say I have a text field (search) and a button ("Get It"). the user simply put info in the jtextfield and intuitively he presses ENTER to proceed. how do i do that?

I tried getIt.getRootPane().setDefaultButton(getIt); but i get a
java.lang.NullPointerException

I don't know how to get the root frame :-(

any idea how to solve it?
thanks
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

One way is to add an actionListener to your JTextField and have it call the same method your JButton's actionListener calls.


GenRocket - Experts at Building Test Data
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Press ENTER and ignit activate the button