Here you can find the source of addFastKeys(JMenuBar menuBar)
public static void addFastKeys(JMenuBar menuBar)
//package com.java2s; // GNU General Public License: // import java.awt.*; import javax.swing.*; public class Main { public static void addFastKeys(JMenuBar menuBar) { for (Component menuComponent : menuBar.getComponents()) { //iterate over menus JMenu menu = (JMenu) menuComponent; menu.setMnemonic(menu.getText().charAt(menu.getText().indexOf('&') + 1)); menu.setText(menu.getText().replace("&", "")); for (Component menuItemComponent : menu.getMenuComponents()) if (menuItemComponent instanceof JMenuItem) { //skip separators JMenuItem menuItem = (JMenuItem) menuItemComponent; menuItem.setMnemonic(menuItem.getText().charAt(menuItem.getText().indexOf('&') + 1)); menuItem.setText(menuItem.getText().replace("&", "")); }/*from w w w .j a va2 s. c o m*/ /* for (int count = 0; count < menu.getMenuComponentCount(); count++) { //iterate over menu items Component menuItemComponent = menu.getMenuComponent(count); if (menuItemComponent instanceof JMenuItem) { //skip separators JMenuItem menuItem = (JMenuItem)menuItemComponent; menuItem.setMnemonic(menuItem.getText().charAt( menuItem.getText().indexOf('&') + 1)); menuItem.setText(menuItem.getText().replace("&", "")); } } */ } } public static void addFastKeys(JButton[] buttonList) { for (JButton button : buttonList) { button.setMnemonic(button.getText().charAt(button.getText().indexOf('&') + 1)); button.setText(button.getText().replace("&", "")); } } }