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

