Setting an accelerator to a JButton

Hi,

I'm having some great diffuiculty trying to set an accelerator / key mapping to a JButton. I'd like it show that when i press ctrl-f an action associated with the button is fired. Any suggestions? At the moment i have:

JButton find =new JButton(new ImageIcon("images/search.gif"));

Action findAction =new AbstractAction(){

publicvoid actionPerformed(ActionEvent e){

System.out.println("HELLO WORLD!");

}

};

KeyStroke ks =null;

InputMap imap = find.getInputMap(WHEN_IN_FOCUSED_WINDOW);

ActionMap amap = find.getActionMap();

ks = KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK);

imap.put(ks, findAction.getValue(Action.NAME));

amap.put(findAction.getValue(Action.NAME), findAction);

many thanks,

BBB

[1178 byte] By [BigBadBurrowa] at [2007-9-30 2:25:15]
# 1
Hi,the action has to have a NAME, like this:Action findAction = new AbstractAction("myFindAction") {...and it works !
andreas.spankusa at 2007-7-16 13:35:03 > top of Java-index,Archived Forums,Swing...
# 2
Excellent!! Thanks so much Andreas
BigBadBurrowa at 2007-7-16 13:35:03 > top of Java-index,Archived Forums,Swing...