Class MenuItemPager


  • public class MenuItemPager
    extends java.lang.Object
    A helper class for creating nested submenus. Usage:
    1. In the constructor provide the target menu to which you want to add items.
    2. Optionally set the number of items per page with setItemsPerPage(int) (default is DEFAULT_ITEMS_PER_PAGE).
    3. Call add(JMenuItem) for each item to add. A new submenu will be created and automatically added to the current (sub)menu as necessary.
    4. Optionally obtain the "first page" of items (the items added directly to the root target menu) with getFirstPage().
    • Constructor Summary

      Constructors 
      Constructor Description
      MenuItemPager​(javax.swing.JMenu menu)  
      MenuItemPager​(javax.swing.JPopupMenu menu)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      javax.swing.JMenuItem add​(javax.swing.JMenuItem newItem)
      Add an item to the menu.
      java.util.List<javax.swing.JMenuItem> getFirstPage()
      Get the "first page" of items (the items added directly to the provided root menu).
      void setItemsPerPage​(int itemsPerPage)
      Set the size of the page (number of items allowed before a new submenu is created).
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

    • Constructor Detail

      • MenuItemPager

        public MenuItemPager​(javax.swing.JPopupMenu menu)
      • MenuItemPager

        public MenuItemPager​(javax.swing.JMenu menu)
    • Method Detail

      • setItemsPerPage

        public void setItemsPerPage​(int itemsPerPage)
        Set the size of the page (number of items allowed before a new submenu is created). The actual number of items added to any (sub)menu is itemsPerPage + 1 for the next submenu.
        Parameters:
        itemsPerPage - Page size
      • add

        public javax.swing.JMenuItem add​(javax.swing.JMenuItem newItem)
        Add an item to the menu. The item will be added to a submenu as appropriate.
        Parameters:
        newItem - The item to add
        Returns:
        The provided item
      • getFirstPage

        public java.util.List<javax.swing.JMenuItem> getFirstPage()
        Get the "first page" of items (the items added directly to the provided root menu). If a second page was added, the list will include the item representing the submenu.
        Returns:
        The first-page items