Class MenuItemPager

java.lang.Object
org.omegat.util.gui.MenuItemPager

public class MenuItemPager extends 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().
  • Field Details

    • DEFAULT_ITEMS_PER_PAGE

      public static final int DEFAULT_ITEMS_PER_PAGE
      See Also:
  • Constructor Details

  • Method Details

    • 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 JMenuItem add(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 List<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