void () { TextWithMnemonic text = TextWithMnemonic.parse(getTitle()); int c = text.getMnemonicCode(); if (c != KeyEvent.VK_UNDEFINED) { myPanel.getActionMap().put(ACTION_KEY, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (myOn) off(); else on(); } }); myPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(c, InputEvent.ALT_MASK, false), ACTION_KEY); } }