Here you can find the source of addFastKeys(JButton[] buttonList)
public static void addFastKeys(JButton[] buttonList)
//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("&", "")); }//w w w . j a v a 2 s.com /* 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("&", "")); } } }