Mnemonics are those underlined letters that you see in labels and buttons that when activated via the ALT key + the letter, will activate that label/button.
However, when a JTable is included in the user interface and has editing capabilities enabled, you may be surprised that instead of activing a button by pressing ALT + key on the keyboard, the JTable activates editing mode.
How to fix it then? You need to override the processKeyBinding() method of the JTable class. Do it like this
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
JTable table = new JTable() { protected boolean processKeyBinding(KeyStroke ks, KeyEvent e, int condition, boolean pressed) { if (checkInvalidKeys(e)) { return false; } return super.processKeyBinding(ks, e, condition, pressed); } private boolean checkInvalidKeys(KeyEvent ke) { if (ke.isAltDown()) return false; else return true; } }); |
This solution was from a forum called Java.net and fixed this mnemonic problem when a JTable with cell editors is present in the same user interface area.