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

JButton from Keyboard  RSS feed

 
Veri Strora
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All!
How can I "click" a JButton from Keyboard with only "F10" (not alt + F10)?
 
Tony Fabeets
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
build a keyListener for the button and use
if(keyEvent.getKeyCode() == KeyEvent.VK_F10){//do something}
keyEvent being the event that has occured and KeyEvent.VK_F10 being the constant for F10. Check out the KeyEvent class in the API
hope this helps
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch Veri!
Take a look at this code:

Thanks to doClick the button is visibly pressed when the user releases the F10 key. If you uncomment the action listener you will see that doClick also fires an actionEvent!
 
Veri Strora
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank You very much to Tony and Jose!
Very useful.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!