This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
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 Murach's Java Servlets and JSP this week in the Servlets 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
 
Similar Threads
coding for response to enter button on keyboard
SET A BUTTON AS "DEFAULT"
Keypressing on console or Dos prompt
Sign in button
KeyListener for a button?