I am trying to use InputMap / ActionMap to intercept the delete key. I get it to work with Enter, but it does not respond to deletion (this is on Mac OSX, so I wonder if this is part of the problem).
What am I doing wrong?
private void setupKeyBindings(final JList jlist) {
String delAction = "deleteItems";
KeyStroke delKey = KeyStroke.getKeyStroke("DELETE");
jlist.getInputMap().put(delKey, delAction);
jlist.getActionMap().put(delAction, new AbstractAction()
{
@Override public void actionPerformed(ActionEvent e) {
System.out.println("delete pressed");
doDelete(jlist);
}
});
String enterAction = "useItems";
KeyStroke enterKey = KeyStroke.getKeyStroke("ENTER");
jlist.getInputMap().put(enterKey, enterAction);
jlist.getActionMap().put(enterAction, new AbstractAction()
{
@Override public void actionPerformed(ActionEvent e) {
System.out.println("enter pressed");
}
});
}
source
share