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

Key listener on jbutton  RSS feed

 
Ankita Dubey
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a Jbutton in my application named as SUBMIT,on clicking SUBMIT the text of jButton changes to ABORT.
I wish to apply enter key listener on both the SUBMIT and ABORT button in my applcation,however i am not able to get the text of the button in key listener,so that i can apply my code based on the current text of Button
help me to do so,
 
Rob Camick
Ranch Hand
Posts: 2800
15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't use a KeyListener.

Instead you should be using Key Bindings. See Enter Key and Button for more information and examples.

In your ActionListener you can use code like the following to get the text of the button that was clicked:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!