Class Menu

java.lang.Object
limn.components.Menu

public final class Menu extends Object
An ordered list of MenuItems: the reusable content of a PopupMenu (context menu / dropdown), a MenuBar top-level entry, or a submenu. Pure model; presenters render it.

 Menu file = new Menu()
     .addItem("New", () -> newDoc())
     .addItem("Open…", () -> open())
     .addSeparator()
     .addSubmenu("Recentes", recentsMenu);
 
  • Constructor Details

    • Menu

      public Menu()
  • Method Details

    • add

      public Menu add(MenuItem item)
      Appends an item, including a separator.
    • addItem

      public Menu addItem(I18nString label, Runnable action)
      Adds a command item.
    • addCheck

      public Menu addCheck(I18nString label, boolean checked, Consumer<Boolean> onToggle)
      A checkable item whose label follows the UI language.
    • addSubmenu

      public Menu addSubmenu(I18nString label, Menu submenu)
      A nested menu whose label follows the UI language.
    • addItem

      public Menu addItem(String label, Runnable action)
      A command item with a fixed label.
    • addCheck

      public Menu addCheck(String label, boolean checked, Consumer<Boolean> onToggle)
      Adds a checkable item.
    • addSubmenu

      public Menu addSubmenu(String label, Menu submenu)
      Adds a submenu item.
    • addSeparator

      public Menu addSeparator()
      Adds a divider (collapsed if it would be leading/trailing/doubled at render time).
    • clear

      public Menu clear()
      Removes every item, so a menu whose contents are data (recent files, open windows, connected devices) can be rebuilt from that data.

      Rebuilt in place rather than replaced, and that is the reason this exists: a MenuBar entry and a MenuItem.submenu both hold the Menu instance, so handing them a fresh one would leave every holder pointing at the list that is no longer current. Clearing bumps modCount() like any other mutation, so a popup already on screen rebuilds its geometry instead of drawing rows that are gone.

    • items

      public List<MenuItem> items()
      The items, in order, an unmodifiable view.
    • isEmpty

      public boolean isEmpty()
      Whether this menu has no items at all.