Class PopupMenu
java.lang.Object
java.awt.MenuComponent
java.awt.MenuItem
java.awt.Menu
java.awt.PopupMenu
- All Implemented Interfaces:
MenuContainer, Serializable, Accessible
A class that implements a menu which can be dynamically popped up
at a specified position within a component.
As the inheritance hierarchy implies, a PopupMenu
can be used anywhere a Menu can be used.
However, if you use a PopupMenu like a Menu
(e.g., you add it to a MenuBar), then you cannot
call show on that PopupMenu.
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classInner class of PopupMenu used to provide default support for accessibility.Nested classes/interfaces declared in class Menu
Menu.AccessibleAWTMenuModifier and TypeClassDescriptionprotected classInner class of Menu used to provide default support for accessibility.Nested classes/interfaces declared in class MenuItem
MenuItem.AccessibleAWTMenuItemModifier and TypeClassDescriptionprotected classInner class of MenuItem used to provide default support for accessibility.Nested classes/interfaces declared in class MenuComponent
MenuComponent.AccessibleAWTMenuComponentModifier and TypeClassDescriptionprotected classInner class ofMenuComponentused to provide default support for accessibility. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCreates the popup menu's peer.Gets theAccessibleContextassociated with thisPopupMenu.voidShows the popup menu at the x, y position relative to an origin component.Methods declared in class Menu
add, add, addSeparator, countItems, getItem, getItemCount, insert, insert, insertSeparator, isTearOff, paramString, remove, remove, removeAll, removeNotifyModifier and TypeMethodDescriptionAdds the specified menu item to this menu.voidAdds an item with the specified label to this menu.voidAdds a separator line, or a hyphen, to the menu at the current position.intDeprecated.getItem(int index) Gets the item located at the specified index of this menu.intGet the number of items in this menu.voidInserts a menu item into this menu at the specified position.voidInserts a menu item with the specified label into this menu at the specified position.voidinsertSeparator(int index) Inserts a separator at the specified position.booleanIndicates whether this menu is a tear-off menu.Returns a string representing the state of thisMenu.voidremove(int index) Removes the menu item at the specified index from this menu.voidremove(MenuComponent item) Removes the specified menu item from this menu.voidRemoves all items from this menu.voidRemoves the menu's peer.Methods declared in class MenuItem
addActionListener, deleteShortcut, disable, disableEvents, enable, enable, enableEvents, getActionCommand, getActionListeners, getLabel, getListeners, getShortcut, isEnabled, processActionEvent, processEvent, removeActionListener, setActionCommand, setEnabled, setLabel, setShortcutModifier and TypeMethodDescriptionvoidAdds the specified action listener to receive action events from this menu item.voidDelete anyMenuShortcutobject associated with this menu item.voiddisable()Deprecated.As of JDK version 1.1, replaced bysetEnabled(boolean).protected final voiddisableEvents(long eventsToDisable) Disables event delivery to this menu item for events defined by the specified event mask parameter.voidenable()Deprecated.As of JDK version 1.1, replaced bysetEnabled(boolean).voidenable(boolean b) Deprecated.As of JDK version 1.1, replaced bysetEnabled(boolean).protected final voidenableEvents(long eventsToEnable) Enables event delivery to this menu item for events to be defined by the specified event mask parameterGets the command name of the action event that is fired by this menu item.Returns an array of all the action listeners registered on this menu item.getLabel()Gets the label for this menu item.<T extends EventListener>
T[]getListeners(Class<T> listenerType) Returns an array of all the objects currently registered asFooListeners upon thisMenuItem.Get theMenuShortcutobject associated with this menu item,booleanChecks whether this menu item is enabled.protected voidProcesses action events occurring on this menu item, by dispatching them to any registeredActionListenerobjects.protected voidProcesses events on this menu item.voidRemoves the specified action listener so it no longer receives action events from this menu item.voidsetActionCommand(String command) Sets the command name of the action event that is fired by this menu item.voidsetEnabled(boolean b) Sets whether or not this menu item can be chosen.voidSets the label for this menu item to the specified label.voidSet theMenuShortcutobject associated with this menu item.Methods declared in class MenuComponent
dispatchEvent, getFont, getName, getParent, getTreeLock, postEvent, setFont, setName, toStringModifier and TypeMethodDescriptionfinal voidDelivers an event to this component or one of its sub components.getFont()Gets the font used for this menu component.getName()Gets the name of the menu component.Returns the parent container for this menu component.protected final ObjectGets this component's locking object (the object that owns the thread synchronization monitor) for AWT component-tree and layout operations.booleanDeprecated.As of JDK version 1.1, replaced bydispatchEvent.voidSets the font to be used for this menu component to the specified font.voidSets the name of the component to the specified string.toString()Returns a representation of this menu component as a string.Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitModifier and TypeMethodDescriptionprotected Objectclone()Answers a new instance of the same class as the receiver, whose slots have been filled in with the values in the slots of the receiver.booleanCompares the argument to the receiver, and answers true if they represent the same object using a class specific comparison.protected voidfinalize()Deprecated, for removal: This API element is subject to removal in a future version.May cause performance issues, deadlocks and hangs.getClass()Answers the unique instance of java.lang.Class which represents the class of the receiver.inthashCode()Answers an integer hash code for the receiver.final voidnotify()Causes one thread which iswaiting on the receiver to be made ready to run.final voidCauses all threads which arewaiting on the receiver to be made ready to run.final voidwait()Causes the thread which sent this message to be made not ready to run pending some change in the receiver (as indicated bynotifyornotifyAll).final voidwait(long time) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.final voidwait(long time, int frac) Causes the thread which sent this message to be made not ready to run either pending some change in the receiver (as indicated bynotifyornotifyAll) or the expiration of the timeout.
-
Constructor Details
-
PopupMenu
Creates a new popup menu with an empty name.- Throws:
HeadlessException- if GraphicsEnvironment.isHeadless() returns true.- See Also:
-
PopupMenu
Creates a new popup menu with the specified name.- Parameters:
label- a non-nullstring specifying the popup menu's label- Throws:
HeadlessException- if GraphicsEnvironment.isHeadless() returns true.- See Also:
-
-
Method Details
-
addNotify
-
show
Shows the popup menu at the x, y position relative to an origin component. The origin component must be contained within the component hierarchy of the popup menu's parent. Both the origin and the parent must be showing on the screen for this method to be valid.If this
PopupMenuis being used as aMenu(i.e., it has a non-Componentparent), then you cannot call this method on thePopupMenu.- Parameters:
origin- the component which defines the coordinate spacex- the x coordinate position to popup the menuy- the y coordinate position to popup the menu- Throws:
NullPointerException- if the parent isnullIllegalArgumentException- if thisPopupMenuhas a non-ComponentparentIllegalArgumentException- if the origin is not in the parent's hierarchyRuntimeException- if the parent is not showing on screen
-
getAccessibleContext
Gets theAccessibleContextassociated with thisPopupMenu.- Specified by:
getAccessibleContextin interfaceAccessible- Overrides:
getAccessibleContextin classMenu- Returns:
- the
AccessibleContextof thisPopupMenu - Since:
- 1.3
-
getItemCount().