Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

want to implement keylistener  RSS feed

 
RaviSingh Kumar
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Design a form which a user should fill and click on submit button to save it into database.I have used ActionListener on submit button.

But i need to implement keylistener.i.e when a user press the return key while focus on submit button ,the event should be performed.

need some help.
 
Qunfeng Wang
Ranch Hand
Posts: 434
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are two options:

1 get used to press Blank Space key instead of Enter key on Windows. You can have a try now!

2 submitButton.setMnemonic(KeyEvent.VK_S), and then you can use Alt + S key.
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you only have the one button with ActionListener,
add this line at the beginning of the constructor

UIManager.put("Button.defaultButtonFollowsFocus",Boolean.TRUE);

works OK in java 1.6, not (apparently) in 1.4, and 1.5 unknown
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!