Here you can find the source of addOption(JPopupMenu popupMenu, String text, String key, ActionListener actionListener)
public static KeyStroke addOption(JPopupMenu popupMenu, String text, String key, ActionListener actionListener)
//package com.java2s; //License from project: Apache License import javax.swing.*; import java.awt.event.ActionListener; public class Main { public static KeyStroke addOption(JPopupMenu popupMenu, String text, String key, ActionListener actionListener) { JMenuItem option = new JMenuItem(text); KeyStroke keyStroke = KeyStroke.getKeyStroke(key); option.setAccelerator(keyStroke); option.addActionListener(actionListener); popupMenu.add(option);//w ww. j a va2s . c om return keyStroke; } }