Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Listening for the enter key in an JTextField?  RSS feed

 
Gulshan Singh
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a text field, and I want to check for the enter key so I can perform an action. I tried a keylistener and then checking to see if the key was the enter key, but that didn't work... I don't know what else to try.
 
Rob Spoor
Sheriff
Posts: 20893
81
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try adding an ActionListener. JTextField will fire an ActionEvent when enter is pressed.
 
Rob Camick
Ranch Hand
Posts: 2752
11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Quit multi-posting and cross-posting questions.

You posted the same question TWICE in the Sun Java forums and where given an answer 10 minutes after you posted the question 12 hours ago so there was absolutely no need to post in this forum.

ignoreList++
 
Campbell Ritchie
Sheriff
Posts: 53743
127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Camick has a point. If you post on several fora you should tell everybody. It is very rude to whoever gave you the answer on the Sun forum. You ought to have told them, and I think you owe them an apology.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!