I provide this for me as a learning experience, as for anyone else. I have always had difficulty using code snippets to bind keys that I found in the past, and I hope that my explanations and code are clear. Thanks to @kleopatra for her piece of code on which I base my code below.
(I use CAPITAL LETTERS, where I DO NOT have to show more clearly what SHOULD CREATE.)
The code associates the Ctrl-Shift-U key Ctrl-Shift-U with the code in actionPerformed for MYACTION via the corresponding lines in getInputMap and getActionMap .
The three instances of MYACTION below should match, as are the four instances of MYACTIONBUTTON , as well as the two instances of the string MAKE_THESE_MATCH . Call them what you want; just make them fit.
The MYACTIONBUTTON button must have MYACTION as an argument to the JButton that defines it AND must have getInputMap and getActionMap to it.
private static JButton MYACTIONBUTTON; private static JFrame frame; private static JPanel panel;
...
Action MYACTION = new AbstractAction() { @Override public void actionPerformed(ActionEvent e) {
source share