* @param submenu Submenu.
* @param begin Number of items kept at the beginning.
* @param end Number of items kept at the end.
*/
public void addSubmenu(JPopupMenu menu, JMenu submenu, int begin, int end) {
Configuration config = Configuration.getConfiguration();
final int maxElements = Math.max(
config.getInt(null, ConfigurationValueInteger.MENU_SIZE),
begin + end + 2);
if (submenu.getMenuComponentCount() > maxElements) {
List<JMenu> menuList = new ArrayList<JMenu>();
while (submenu.getMenuComponentCount() > begin + end + 1) {
int count = Math.min(maxElements, submenu.getMenuComponentCount() - begin - end);