APIdia Launch Partner
Top Description Inners Fields Constructors Methods
java.awt

public Class PopupMenu

extends Menu
Class Inheritance
Imports
java.awt.peer.PopupMenuPeer, java.io.Serial, javax.accessibility.AccessibleContext, .AccessibleRole, sun.awt.AWTAccessor

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.

Author
Amy Fowler

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected class
PopupMenu.AccessibleAWTPopupMenu

Inner class of PopupMenu used to provide default support for accessibility.

Field Summary

Modifier and TypeField and Description
private static final String
pack-priv transient volatile boolean
pack-priv static int
private static final long
serialVersionUID

Hides java.awt.Menu.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.
Inherited from java.awt.Menu:
isHelpMenu

Constructor Summary

AccessConstructor and Description
public
PopupMenu()

Creates a new popup menu with an empty name.

public
PopupMenu(String
a non-null string specifying the popup menu's label
label
)

Creates a new popup menu with the specified name.

Method Summary

Modifier and TypeMethod and Description
public void
addNotify()

Overrides java.awt.Menu.addNotify.

Creates the popup menu's peer.

pack-priv String
constructComponentName()

Overrides java.awt.Menu.constructComponentName.

Constructs a name for this MenuComponent.

public AccessibleContext

Returns:

the AccessibleContext of this PopupMenu
getAccessibleContext
()

Overrides java.awt.Menu.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this PopupMenu.

public MenuContainer
getParent()

Overrides java.awt.MenuComponent.getParent.

Returns the parent container for this menu component.

public void
show(Component
the component which defines the coordinate space
origin
,
int
the x coordinate position to popup the menu
x
,
int
the y coordinate position to popup the menu
y
)

Shows the popup menu at the x, y position relative to an origin component.

Inherited from java.awt.Menu:
addaddaddSeparatorcountItemscountItemsImpldeleteShortcutgetAccessibleChildIndexgetItemgetItemCountgetItemImplgetShortcutMenuItemhandleShortcutinsertinsertinsertSeparatorisTearOffparamStringremoveremoveremoveAllremoveNotifyshortcuts

Field Detail

baseback to summary
private static final String base

Hides java.awt.Menu.base.

isTrayIconPopupback to summary
pack-priv transient volatile boolean isTrayIconPopup
nameCounterback to summary
pack-priv static int nameCounter

Hides java.awt.Menu.nameCounter.

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.Menu.serialVersionUID.

Use serialVersionUID from JDK 1.1 for interoperability.

Annotations
@Serial

Constructor Detail

PopupMenuback to summary
public PopupMenu() throws HeadlessException

Creates a new popup menu with an empty name.

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true.
See Also
java.awt.GraphicsEnvironment#isHeadless
PopupMenuback to summary
public PopupMenu(String label) throws HeadlessException

Creates a new popup menu with the specified name.

Parameters
label:String

a non-null string specifying the popup menu's label

Exceptions
HeadlessException:
if GraphicsEnvironment.isHeadless() returns true.
See Also
java.awt.GraphicsEnvironment#isHeadless

Method Detail

addNotifyback to summary
public void addNotify()

Overrides java.awt.Menu.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.

constructComponentNameback to summary
pack-priv String constructComponentName()

Overrides java.awt.Menu.constructComponentName.

Constructs a name for this MenuComponent. Called by getName when the name is null.

getAccessibleContextback to summary
public AccessibleContext getAccessibleContext()

Overrides java.awt.Menu.getAccessibleContext.

Implements javax.accessibility.Accessible.getAccessibleContext.

Gets the AccessibleContext associated with this PopupMenu.

Returns:AccessibleContext

the AccessibleContext of this PopupMenu

Since
1.3
getParentback to summary
public MenuContainer getParent()

Overrides java.awt.MenuComponent.getParent.

Doc from java.awt.MenuComponent.getParent.

Returns the parent container for this menu component.

showback to summary
public void show(Component 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:Component

the component which defines the coordinate space

x:int

the x coordinate position to popup the menu

y:int

the y coordinate position to popup the menu

Annotations
@SuppressWarnings:deprecation
Exceptions
NullPointerException:
if the parent is null
IllegalArgumentException:
  • if this PopupMenu has a non-Component parent
  • if the origin is not in the parent's hierarchy
RuntimeException:
if the parent is not showing on screen
java.awt back to summary

protected Class PopupMenu.AccessibleAWTPopupMenu

extends AccessibleAWTMenu
Class Inheritance

Inner class of PopupMenu used to provide default support for accessibility. This class is not meant to be used directly by application developers, but is instead meant only to be subclassed by menu component developers.

The class used to obtain the accessible role for this object.

Since
1.3

Field Summary

Modifier and TypeField and Description
private static final long
serialVersionUID

Hides java.awt.Menu.AccessibleAWTMenu.serialVersionUID.

Use serialVersionUID from JDK 1.3 for interoperability.

Constructor Summary

AccessConstructor and Description
protected
AccessibleAWTPopupMenu()

Constructs an AccessibleAWTPopupMenu.

Method Summary

Modifier and TypeMethod and Description
public AccessibleRole

Returns:

an instance of AccessibleRole describing the role of the object
getAccessibleRole
()

Overrides java.awt.Menu.AccessibleAWTMenu.getAccessibleRole.

Get the role of this object.

Field Detail

serialVersionUIDback to summary
private static final long serialVersionUID

Hides java.awt.Menu.AccessibleAWTMenu.serialVersionUID.

Use serialVersionUID from JDK 1.3 for interoperability.

Annotations
@Serial

Constructor Detail

AccessibleAWTPopupMenuback to summary
protected AccessibleAWTPopupMenu()

Constructs an AccessibleAWTPopupMenu.

Method Detail

getAccessibleRoleback to summary
public AccessibleRole getAccessibleRole()

Overrides java.awt.Menu.AccessibleAWTMenu.getAccessibleRole.

Get the role of this object.

Returns:AccessibleRole

an instance of AccessibleRole describing the role of the object