|
-
May 9th, 2012, 05:14 PM
#1
Key binding - listening for 2 keys
How do I develop my code to listen for F5 and F10, so if F5 is pressed run 'runSQL(conn, sqlStatement.getText().trim());' otherwise if F10 is pressed run 'runUpdateQuery(conn, sqlStatement.getText().trim());'
Thanks
Code:
AbstractAction action = new AbstractAction() {
public void actionPerformed(ActionEvent e) {
runSQL(conn, sqlStatement.getText().trim());
}
};
// F5 key bind to run the SQL
String keyStrokeAndKey = "F5";
KeyStroke keyStroke = KeyStroke.getKeyStroke(keyStrokeAndKey);
InputMap im = pnlMain
.getInputMap(JPanel.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
im.put(keyStroke, keyStrokeAndKey);
pnlMain.getActionMap().put(keyStrokeAndKey, action);
-
May 10th, 2012, 12:50 PM
#2
Re: Key binding - listening for 2 keys
-
May 10th, 2012, 02:28 PM
#3
Re: Key binding - listening for 2 keys
Thank you - that's perfect!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|