Class CheckBoxMenu

All Implemented Interfaces:
ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible, ListSelectionListener, MenuElement, SwingConstants

public class CheckBoxMenu extends JMenu implements ListSelectionListener
A menu which contains only checkbox-type entries and has an associated ListSelectionModel.
See Also:
  • Constructor Details

    • CheckBoxMenu

      public CheckBoxMenu()
      Constructs a new CheckBoxMenu.
    • CheckBoxMenu

      public CheckBoxMenu(String name)
      Constructs a new CheckBoxMenu with a given name.
      Parameters:
      name - the menu name
  • Method Details

    • getEntryCount

      public int getEntryCount()
      Returns the number of tickable entries in the menu.
      Returns:
      number of entries
    • addListSelectionListener

      public void addListSelectionListener(ListSelectionListener listener)
    • removeListSelectionListener

      public void removeListSelectionListener(ListSelectionListener listener)
    • addMenuItem

      public void addMenuItem(String text)
      Adds an item to the menu. The item will be represented as a checkbox menu item; ticking/unticking it will cause this object's selection model to be updated (and vice versa).
      Parameters:
      text - the label for the next item on the menu
    • getSelectionModel

      public ListSelectionModel getSelectionModel()
      Returns the selection model used to keep track of the ticked/unticked status of the checkboxes in this menu.
      Returns:
      the selection model
    • setSelectionModel

      public void setSelectionModel(ListSelectionModel selModel)
      Sets the selection model used to keep track of the ticked/unticked status of the checkboxes in this menu. You can slot your own model in here, any previous one is discarded by this object.
      Parameters:
      selModel - the new selection model
    • valueChanged

      public void valueChanged(ListSelectionEvent evt)
      Specified by:
      valueChanged in interface ListSelectionListener