Class PopupMenu

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible, MenuElement

    public class PopupMenu
    extends JPopupMenu
    Convenience class for constructing popup menus. Example: add to a JTable: JTable jtable = table.getJTable(); PopupMenu csPopup = new PopupMenu(jtable, "Options"); csPopup.addAction("Show Declaration", new AbstractAction() { public void actionPerformed(ActionEvent e) { showDeclaration(table); } });
    See Also:
    Serialized Form
    • Constructor Detail

      • PopupMenu

        public PopupMenu​(JComponent parent,
                         String menuTitle)
        Constructor.
        Parameters:
        parent - A MouseListener is added to this JComponent.
        menuTitle - title of the popup menu.
      • PopupMenu

        public PopupMenu​(JComponent parent,
                         String menuTitle,
                         boolean anyButton)
        Constructor.
        Parameters:
        parent - A MouseListener is added to this JComponent.
        menuTitle - title of the popup menu.
        anyButton - if true, any button activates, otherwise use MouseEvent.isPopupTrigger
    • Method Detail

      • addAction

        public void addAction​(String menuName,
                              Action act)
        Add an action to the popup menu. Note that the menuName is made the NAME value of the action.
        Parameters:
        menuName - name of the action on the menu.
        act - the Action.
      • addAction

        public void addAction​(String menuName,
                              String iconName,
                              Action act)
        Add an action to the popup menu, with an icon. Note that the menuName is made the NAME value of the action.
        Parameters:
        menuName - name of the action on the menu.
        act - the Action.
      • addAction

        public void addAction​(String menuName,
                              ImageIcon icon,
                              Action act)
        Add an action to the popup menu, with an icon. Note that the menuName is made the NAME value of the action.
        Parameters:
        menuName - name of the action on the menu.
        act - the Action.
      • addActionCheckBox

        public void addActionCheckBox​(String menuName,
                                      AbstractAction act,
                                      boolean state)
        Add an action to the popup menu, using a JCheckBoxMenuItem. Fetch the toggle state using:
         Boolean state = (Boolean) act.getValue(BAMutil.STATE);
         
        Parameters:
        menuName - name of the action on the menu.
        act - the Action.
        state - : initial state of the checkbox
      • getParentComponent

        public JComponent getParentComponent()