What is the best way to define the actions for lots of key mappings for a component in Swing?
I built my own Text View in Swing and want to define actions for a lot of keys. The way I'm currently doing it (for around 10 keys so far) is:
ActionMap actionMap = DBDocument.this.getActionMap();
int condition = JComponent.WHEN_FOCUSED;
InputMap inputMap = DBDocument.this.getInputMap(condition);
String tab = "tab";
actionMap.put(tab, new AbstractAction() {
private static final long serialVersionUID = 1L;
@Override
public void actionPerformed(ActionEvent ap) {
if(mDocumentModel != null){
//Do some stuff here
}
}
});
This is obviously a very verbose way of defining key bindings. Ideally I would be able to define an action that deals with lots of possibilities (e.g. [A-Z] or [0-9]). I've searched for definitions in the OpenJDK but didn't get very far.