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

Changing keymappings in swing GUIs  RSS feed

 
Michael Fitzmaurice
Ranch Hand
Posts: 168
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all
I have written an application that uses swing components as the front-end to a database. However, users being what they are, they have requested that the key used to "click" buttons be changed from the default (space bar on Win32) to the Return key.
I am looking for a decent way to do this. With standard JButtons, I have come up with the hack of extending the JButton class and adding a key listener which calls the doClick() method in response to the user hitting the return key when the button has focus. Fine.
However, I am also making extensive use of JOptionPane static methods, whereby I just pass in an array of Strings and the rest is done for me. I know I could replace the array of Strings with an array of my extended JButton class objects, but this seems like an ugly solution involving unnecessary extra coding.
I can't help feeling that there is a simple way to achieve this - can anybody point me in the right direction?
Many thanks
Michael
------------------
"One good thing about music - when it hits, you feel no pain"
Bob Marley
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!