aspose file tools
The moose likes Swing / AWT / SWT / JFace and the fly likes Changing keymappings in swing GUIs Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT / JFace
Reply Bookmark "Changing keymappings in swing GUIs" Watch "Changing keymappings in swing GUIs" New topic
Author

Changing keymappings in swing GUIs

Michael Fitzmaurice
Ranch Hand

Joined: Aug 22, 2001
Posts: 168
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


"One good thing about music - when it hits, you feel no pain" <P>Bob Marley
 
 
subject: Changing keymappings in swing GUIs
 
Threads others viewed
retreiving contents of JTextFields for logic
Array of Strings problem
Mouse shift event coding - to trigger a predetermined sequence of images to a GUI
KeyListener Issue
Bi-directional Map
IntelliJ Java IDE