PopupMenu (Java Platform SE 8 ) (original) (raw)
- java.awt.MenuComponent
- java.awt.MenuItem
- java.awt.Menu
* * java.awt.PopupMenu
- java.awt.Menu
- java.awt.MenuItem
All Implemented Interfaces:
MenuContainer, Serializable, Accessible
public class PopupMenu
extends Menu
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:
Serialized Form
Nested Class Summary
Nested Classes
Modifier and Type Class Description protected class PopupMenu.AccessibleAWTPopupMenu Inner class of PopupMenu used to provide default support for accessibility. * ### Nested classes/interfaces inherited from class java.awt.[Menu](../../java/awt/Menu.html "class in java.awt") `[Menu.AccessibleAWTMenu](../../java/awt/Menu.AccessibleAWTMenu.html "class in java.awt")` * ### Nested classes/interfaces inherited from class java.awt.[MenuItem](../../java/awt/MenuItem.html "class in java.awt") `[MenuItem.AccessibleAWTMenuItem](../../java/awt/MenuItem.AccessibleAWTMenuItem.html "class in java.awt")` * ### Nested classes/interfaces inherited from class java.awt.[MenuComponent](../../java/awt/MenuComponent.html "class in java.awt") `[MenuComponent.AccessibleAWTMenuComponent](../../java/awt/MenuComponent.AccessibleAWTMenuComponent.html "class in java.awt")`
Constructor Summary
Constructors
Constructor Description PopupMenu() Creates a new popup menu with an empty name. PopupMenu(String label) Creates a new popup menu with the specified name. Method Summary
All Methods Instance Methods Concrete Methods
Modifier and Type Method Description void addNotify() Creates the popup menu's peer. AccessibleContext getAccessibleContext() Gets the AccessibleContext associated with thisPopupMenu. MenuContainer getParent() Returns the parent container for this menu component. void show(Component origin, int x, int y) Shows the popup menu at the x, y position relative to an origin component. * ### Methods inherited from class java.awt.[Menu](../../java/awt/Menu.html "class in java.awt") `[add](../../java/awt/Menu.html#add-java.awt.MenuItem-), [add](../../java/awt/Menu.html#add-java.lang.String-), [addSeparator](../../java/awt/Menu.html#addSeparator--), [countItems](../../java/awt/Menu.html#countItems--), [getItem](../../java/awt/Menu.html#getItem-int-), [getItemCount](../../java/awt/Menu.html#getItemCount--), [insert](../../java/awt/Menu.html#insert-java.awt.MenuItem-int-), [insert](../../java/awt/Menu.html#insert-java.lang.String-int-), [insertSeparator](../../java/awt/Menu.html#insertSeparator-int-), [isTearOff](../../java/awt/Menu.html#isTearOff--), [paramString](../../java/awt/Menu.html#paramString--), [remove](../../java/awt/Menu.html#remove-int-), [remove](../../java/awt/Menu.html#remove-java.awt.MenuComponent-), [removeAll](../../java/awt/Menu.html#removeAll--), [removeNotify](../../java/awt/Menu.html#removeNotify--)` * ### Methods inherited from class java.awt.[MenuItem](../../java/awt/MenuItem.html "class in java.awt") `[addActionListener](../../java/awt/MenuItem.html#addActionListener-java.awt.event.ActionListener-), [deleteShortcut](../../java/awt/MenuItem.html#deleteShortcut--), [disable](../../java/awt/MenuItem.html#disable--), [disableEvents](../../java/awt/MenuItem.html#disableEvents-long-), [enable](../../java/awt/MenuItem.html#enable--), [enable](../../java/awt/MenuItem.html#enable-boolean-), [enableEvents](../../java/awt/MenuItem.html#enableEvents-long-), [getActionCommand](../../java/awt/MenuItem.html#getActionCommand--), [getActionListeners](../../java/awt/MenuItem.html#getActionListeners--), [getLabel](../../java/awt/MenuItem.html#getLabel--), [getListeners](../../java/awt/MenuItem.html#getListeners-java.lang.Class-), [getShortcut](../../java/awt/MenuItem.html#getShortcut--), [isEnabled](../../java/awt/MenuItem.html#isEnabled--), [processActionEvent](../../java/awt/MenuItem.html#processActionEvent-java.awt.event.ActionEvent-), [processEvent](../../java/awt/MenuItem.html#processEvent-java.awt.AWTEvent-), [removeActionListener](../../java/awt/MenuItem.html#removeActionListener-java.awt.event.ActionListener-), [setActionCommand](../../java/awt/MenuItem.html#setActionCommand-java.lang.String-), [setEnabled](../../java/awt/MenuItem.html#setEnabled-boolean-), [setLabel](../../java/awt/MenuItem.html#setLabel-java.lang.String-), [setShortcut](../../java/awt/MenuItem.html#setShortcut-java.awt.MenuShortcut-)` * ### Methods inherited from class java.awt.[MenuComponent](../../java/awt/MenuComponent.html "class in java.awt") `[dispatchEvent](../../java/awt/MenuComponent.html#dispatchEvent-java.awt.AWTEvent-), [getFont](../../java/awt/MenuComponent.html#getFont--), [getName](../../java/awt/MenuComponent.html#getName--), [getPeer](../../java/awt/MenuComponent.html#getPeer--), [getTreeLock](../../java/awt/MenuComponent.html#getTreeLock--), [postEvent](../../java/awt/MenuComponent.html#postEvent-java.awt.Event-), [setFont](../../java/awt/MenuComponent.html#setFont-java.awt.Font-), [setName](../../java/awt/MenuComponent.html#setName-java.lang.String-), [toString](../../java/awt/MenuComponent.html#toString--)` * ### Methods inherited from class java.lang.[Object](../../java/lang/Object.html "class in java.lang") `[clone](../../java/lang/Object.html#clone--), [equals](../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../java/lang/Object.html#finalize--), [getClass](../../java/lang/Object.html#getClass--), [hashCode](../../java/lang/Object.html#hashCode--), [notify](../../java/lang/Object.html#notify--), [notifyAll](../../java/lang/Object.html#notifyAll--), [wait](../../java/lang/Object.html#wait--), [wait](../../java/lang/Object.html#wait-long-), [wait](../../java/lang/Object.html#wait-long-int-)` * ### Methods inherited from interface java.awt.[MenuContainer](../../java/awt/MenuContainer.html "interface in java.awt") `[getFont](../../java/awt/MenuContainer.html#getFont--), [postEvent](../../java/awt/MenuContainer.html#postEvent-java.awt.Event-)`
Constructor Detail
* #### PopupMenu public PopupMenu() throws [HeadlessException](../../java/awt/HeadlessException.html "class in java.awt") Creates a new popup menu with an empty name. Throws: `[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt")` \- if GraphicsEnvironment.isHeadless() returns true. See Also: [GraphicsEnvironment.isHeadless()](../../java/awt/GraphicsEnvironment.html#isHeadless--) * #### PopupMenu public PopupMenu([String](../../java/lang/String.html "class in java.lang") label) throws [HeadlessException](../../java/awt/HeadlessException.html "class in java.awt") Creates a new popup menu with the specified name. Parameters: `label` \- a non-`null` string specifying the popup menu's label Throws: `[HeadlessException](../../java/awt/HeadlessException.html "class in java.awt")` \- if GraphicsEnvironment.isHeadless() returns true. See Also: [GraphicsEnvironment.isHeadless()](../../java/awt/GraphicsEnvironment.html#isHeadless--)
Method Detail
* #### getParent public [MenuContainer](../../java/awt/MenuContainer.html "interface in java.awt") getParent() Returns the parent container for this menu component. Overrides: `[getParent](../../java/awt/MenuComponent.html#getParent--)` in class `[MenuComponent](../../java/awt/MenuComponent.html "class in java.awt")` Returns: the menu component containing this menu component, or `null` if this menu component is the outermost component, the menu bar itself * #### addNotify public void addNotify() Creates the popup menu's peer. The peer allows us to change the appearance of the popup menu without changing any of the popup menu's functionality. Overrides: `[addNotify](../../java/awt/Menu.html#addNotify--)` in class `[Menu](../../java/awt/Menu.html "class in java.awt")` * #### show public void show([Component](../../java/awt/Component.html "class in java.awt") origin, int x, int y) 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 `PopupMenu` is being used as a `Menu` (i.e., it has a non-`Component` parent), then you cannot call this method on the `PopupMenu`. Parameters: `origin` \- the component which defines the coordinate space `x` \- the x coordinate position to popup the menu `y` \- the y coordinate position to popup the menu Throws: `[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if the parent is `null` `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if this `PopupMenu` has a non-`Component` parent `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if the origin is not in the parent's hierarchy `[RuntimeException](../../java/lang/RuntimeException.html "class in java.lang")` \- if the parent is not showing on screen * #### getAccessibleContext public [AccessibleContext](../../javax/accessibility/AccessibleContext.html "class in javax.accessibility") getAccessibleContext() Gets the `AccessibleContext` associated with this`PopupMenu`. Specified by: `[getAccessibleContext](../../javax/accessibility/Accessible.html#getAccessibleContext--)` in interface `[Accessible](../../javax/accessibility/Accessible.html "interface in javax.accessibility")` Overrides: `[getAccessibleContext](../../java/awt/Menu.html#getAccessibleContext--)` in class `[Menu](../../java/awt/Menu.html "class in java.awt")` Returns: the `AccessibleContext` of this`PopupMenu` Since: 1.3
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.