Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Press ENTER and ignit activate the button

 
Peter Primrose
Ranch Hand
Posts: 755
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15302
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One way is to add an actionListener to your JTextField and have it call the same method your JButton's actionListener calls.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic