Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Press ENTER and ignit activate the button  RSS feed

 
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
Ranch Hand
Posts: 15304
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!