void (JComponent component, int index) { try { Method method = component.getClass().getMethod("setDisplayedMnemonicIndex", int.class); method.setAccessible(true); method.invoke(component, Integer.valueOf(index)); } catch (Exception e) { // JDK earlier than 1.4 - do nothing } }