private static boolean hasMnemonic(final Container container, final int keyCode) { if (container == null) return false; final Component[] components = container.getComponents(); for (Component component : components) { if (component instanceof AbstractButton) { final AbstractButton button = (AbstractButton)component; if (button instanceof JBOptionButton) { if (((JBOptionButton)button).isOkToProcessDefaultMnemonics()) return true; } else { if (button.getMnemonic() == keyCode) return true; } } if (component instanceof JLabel) { final JLabel label = (JLabel)component; if (label.getDisplayedMnemonic() == keyCode) return true; } if (component instanceof Container) { if (hasMnemonic((Container)component, keyCode)) return true; } } return false; }