java.lang.Object | ||||
↳ | java.awt.Component | |||
↳ | java.awt.Container | |||
↳ | javax.swing.JComponent | |||
↳ | javax.swing.JPopupMenu |
![]() |
![]() |
An implementation of a popup menu -- a small window that pops up
and displays a series of choices. A JPopupMenu
is used for the
menu that appears when the user selects an item on the menu bar.
It is also used for "pull-right" menu that appears when the
selects a menu item that activates it. Finally, a JPopupMenu
can also be used anywhere else you want a menu to appear. For
example, when the user right-clicks in a specified area.
For information and examples of using popup menus, see How to Use Menus in The Java Tutorial.
Warning: Swing is not thread safe. For more information see Swing's Threading Policy.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans
package.
Please see XMLEncoder
.
Nested Classes | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
JPopupMenu.AccessibleJPopupMenu | This class implements accessibility support for the
JPopupMenu class. |
||||||||||
JPopupMenu.Separator | A popup menu-specific separator. |
[Expand]
Inherited Constants | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() |
[Expand]
Inherited Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a
JPopupMenu without an "invoker". | |||||||||||
Constructs a
JPopupMenu with the specified title. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Appends the specified menu item to the end of this menu.
| |||||||||||
Appends a new menu item to the end of the menu which
dispatches the specified
Action object. | |||||||||||
Creates a new menu item with the specified text and appends
it to the end of this menu.
| |||||||||||
Adds a
MenuKeyListener to the popup menu. | |||||||||||
Adds a
PopupMenu listener. | |||||||||||
Appends a new separator at the end of the menu.
| |||||||||||
Gets the AccessibleContext associated with this JPopupMenu.
| |||||||||||
Returns this
JPopupMenu component. | |||||||||||
This method is deprecated.
replaced by
getComponent(int)
| |||||||||||
Returns the index of the specified component.
| |||||||||||
Gets the
defaultLightWeightPopupEnabled property,
which by default is true . | |||||||||||
Returns the component which is the 'invoker' of this
popup menu.
| |||||||||||
Returns the popup menu's label
| |||||||||||
Returns the margin, in pixels, between the popup menu's border and
its containees.
| |||||||||||
Returns an array of all the
MenuKeyListener s added
to this JPopupMenu with addMenuKeyListener(). | |||||||||||
Returns an array of all the
PopupMenuListener s added
to this JMenuItem with addPopupMenuListener(). | |||||||||||
Returns the model object that handles single selections.
| |||||||||||
Returns an array of
MenuElement s containing the submenu
for this menu component. | |||||||||||
Returns the look and feel (L&F) object that renders this component.
| |||||||||||
Returns the name of the L&F class that renders this component.
| |||||||||||
Inserts a menu item for the specified
Action object at
a given position. | |||||||||||
Inserts the specified component into the menu at a given
position.
| |||||||||||
Checks whether the border should be painted.
| |||||||||||
Gets the
lightWeightPopupEnabled property. | |||||||||||
Returns true if the
MouseEvent is considered a popup trigger
by the JPopupMenu 's currently installed UI. | |||||||||||
Returns true if the popup menu is visible (currently
being displayed).
| |||||||||||
Messaged when the menubar selection changes to activate or
deactivate this menu.
| |||||||||||
Lays out the container so that it uses the minimum space
needed to display its contents.
| |||||||||||
Processes a key event forwarded from the
MenuSelectionManager and changes the menu selection,
if necessary, by using MenuSelectionManager 's API. | |||||||||||
This method is required to conform to the
MenuElement interface, but it not implemented. | |||||||||||
Removes the component at the specified index from this popup menu.
| |||||||||||
Removes a
MenuKeyListener from the popup menu. | |||||||||||
Removes a
PopupMenu listener. | |||||||||||
Sets whether the border should be painted.
| |||||||||||
Sets the default value of the
lightWeightPopupEnabled
property. | |||||||||||
Sets the invoker of this popup menu -- the component in which
the popup menu menu is to be displayed.
| |||||||||||
Sets the popup menu's label.
| |||||||||||
Sets the value of the
lightWeightPopupEnabled property,
which by default is true . | |||||||||||
Sets the location of the upper left corner of the
popup menu using x, y coordinates.
| |||||||||||
Sets the size of the Popup window using a
Dimension object. | |||||||||||
Sets the size of the Popup window to the specified width and
height.
| |||||||||||
Sets the currently selected component, This will result
in a change to the selection model.
| |||||||||||
Sets the model object to handle single selections.
| |||||||||||
Sets the L&F object that renders this component.
| |||||||||||
Sets the visibility of the popup menu.
| |||||||||||
Displays the popup menu at the position x,y in the coordinate
space of the component invoker.
| |||||||||||
Resets the UI property to a value from the current look and feel.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Returns a properly configured
PropertyChangeListener
which updates the control as changes to the Action occur. | |||||||||||
Factory method which creates the
JMenuItem for
Actions added to the JPopupMenu . | |||||||||||
Notifies
PopupMenuListeners that this popup menu is
cancelled. | |||||||||||
Notifies
PopupMenuListener s that this popup menu will
become invisible. | |||||||||||
Notifies
PopupMenuListener s that this popup menu will
become visible. | |||||||||||
Paints the popup menu's border if the
borderPainted
property is true . | |||||||||||
Returns a string representation of this
JPopupMenu . | |||||||||||
Processes focus events occurring on this component by
dispatching them to any registered
FocusListener objects. | |||||||||||
Processes key stroke events such as mnemonics and accelerators.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() | |||||||||||
![]() |
Constructs a JPopupMenu
without an "invoker".
Constructs a JPopupMenu
with the specified title.
label | the string that a UI may use to display as a title for the popup menu. |
---|
Appends the specified menu item to the end of this menu.
menuItem | the JMenuItem to add |
---|
JMenuItem
added
Appends a new menu item to the end of the menu which
dispatches the specified Action
object.
a | the Action to add to the menu |
---|
Creates a new menu item with the specified text and appends it to the end of this menu.
s | the string for the menu item to be added |
---|
Adds a MenuKeyListener
to the popup menu.
l | the MenuKeyListener to be added |
---|
Adds a PopupMenu
listener.
l | the PopupMenuListener to add
|
---|
Appends a new separator at the end of the menu.
Gets the AccessibleContext associated with this JPopupMenu. For JPopupMenus, the AccessibleContext takes the form of an AccessibleJPopupMenu. A new AccessibleJPopupMenu instance is created if necessary.
This method is deprecated.
replaced by getComponent(int)
Returns the component at the specified index.
i | the index of the component, where 0 is the first |
---|
Component
at that indexReturns the index of the specified component.
c | the Component to find |
---|
Gets the defaultLightWeightPopupEnabled
property,
which by default is true
.
defaultLightWeightPopupEnabled
propertyReturns the component which is the 'invoker' of this popup menu.
Component
in which the popup menu is displayed
Returns the popup menu's label
Returns the margin, in pixels, between the popup menu's border and its containees.
Insets
object containing the margin values.
Returns an array of all the MenuKeyListener
s added
to this JPopupMenu with addMenuKeyListener().
MenuKeyListener
s added or an empty
array if no listeners have been addedReturns an array of all the PopupMenuListener
s added
to this JMenuItem with addPopupMenuListener().
PopupMenuListener
s added or an empty
array if no listeners have been addedReturns the model object that handles single selections.
selectionModel
propertyReturns an array of MenuElement
s containing the submenu
for this menu component. It will only return items conforming to
the JMenuElement
interface.
If popup menu is null
returns
an empty array. This method is required to conform to the
MenuElement
interface.
MenuElement
objectsReturns the look and feel (L&F) object that renders this component.
PopupMenuUI
object that renders this component
Returns the name of the L&F class that renders this component.
Inserts a menu item for the specified Action
object at
a given position.
a | the Action object to insert |
---|---|
index | specifies the position at which to insert the
Action , where 0 is the first |
IllegalArgumentException | if index < 0 |
---|
Inserts the specified component into the menu at a given position.
component | the Component to insert |
---|---|
index | specifies the position at which to insert the component, where 0 is the first |
IllegalArgumentException | if index < 0
|
---|
Checks whether the border should be painted.
Gets the lightWeightPopupEnabled
property.
lightWeightPopupEnabled
propertyReturns true if the MouseEvent
is considered a popup trigger
by the JPopupMenu
's currently installed UI.
Returns true if the popup menu is visible (currently being displayed).
true
if the component is visible,
false
otherwiseMessaged when the menubar selection changes to activate or
deactivate this menu. This implements the
javax.swing.MenuElement
interface.
Overrides MenuElement.menuSelectionChanged
.
isIncluded | true if this menu is active, false if it is not |
---|
Lays out the container so that it uses the minimum space needed to display its contents.
Processes a key event forwarded from the
MenuSelectionManager
and changes the menu selection,
if necessary, by using MenuSelectionManager
's API.
Note: you do not have to forward the event to sub-components.
This is done automatically by the MenuSelectionManager
.
e | a KeyEvent |
---|---|
path | the MenuElement path array |
manager | the MenuSelectionManager
|
This method is required to conform to the
MenuElement
interface, but it not implemented.
Removes the component at the specified index from this popup menu.
pos | the position of the item to be removed |
---|
IllegalArgumentException | if the value of
pos < 0, or if the value of
pos is greater than the
number of items
|
---|
Removes a MenuKeyListener
from the popup menu.
l | the MenuKeyListener to be removed |
---|
Removes a PopupMenu
listener.
l | the PopupMenuListener to remove
|
---|
Sets whether the border should be painted.
b | if true, the border is painted. |
---|
Sets the default value of the lightWeightPopupEnabled
property.
aFlag | true if popups can be lightweight,
otherwise false |
---|
Sets the invoker of this popup menu -- the component in which the popup menu menu is to be displayed.
invoker | the Component in which the popup
menu is displayed |
---|
Sets the popup menu's label. Different look and feels may choose to display or not display this.
label | a string specifying the label for the popup menu |
---|
Sets the value of the lightWeightPopupEnabled
property,
which by default is true
.
By default, when a look and feel displays a popup,
it can choose to
use a lightweight (all-Java) popup.
Lightweight popup windows are more efficient than heavyweight
(native peer) windows,
but lightweight and heavyweight components do not mix well in a GUI.
If your application mixes lightweight and heavyweight components,
you should disable lightweight popups.
Some look and feels might always use heavyweight popups,
no matter what the value of this property.
aFlag | false to disable lightweight popups |
---|
Sets the location of the upper left corner of the popup menu using x, y coordinates.
x | the x coordinate of the popup's new position in the screen's coordinate space |
---|---|
y | the y coordinate of the popup's new position in the screen's coordinate space |
Sets the size of the Popup window using a Dimension
object.
This is equivalent to setPreferredSize(d)
.
d | the Dimension specifying the new size
of this component. |
---|
Sets the size of the Popup window to the specified width and
height. This is equivalent to
setPreferredSize(new Dimension(width, height))
.
width | the new width of the Popup in pixels |
---|---|
height | the new height of the Popup in pixels |
Sets the currently selected component, This will result in a change to the selection model.
sel | the Component to select |
---|
Sets the model object to handle single selections.
model | the new SingleSelectionModel |
---|
Sets the L&F object that renders this component.
ui | the new PopupMenuUI L&F object |
---|
Sets the visibility of the popup menu.
b | true to make the popup visible, or false to hide it |
---|
Displays the popup menu at the position x,y in the coordinate space of the component invoker.
invoker | the component in whose space the popup menu is to appear |
---|---|
x | the x coordinate in invoker's coordinate space at which the popup menu is to be displayed |
y | the y coordinate in invoker's coordinate space at which the popup menu is to be displayed |
Resets the UI property to a value from the current look and feel.
Returns a properly configured PropertyChangeListener
which updates the control as changes to the Action
occur.
Factory method which creates the JMenuItem
for
Actions
added to the JPopupMenu
.
a | the Action for the menu item to be added |
---|
Notifies PopupMenuListeners
that this popup menu is
cancelled.
Notifies PopupMenuListener
s that this popup menu will
become invisible.
Notifies PopupMenuListener
s that this popup menu will
become visible.
Paints the popup menu's border if the borderPainted
property is true
.
g | the Graphics object |
---|
Returns a string representation of this JPopupMenu
.
This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null
.
JPopupMenu
.
Processes focus events occurring on this component by
dispatching them to any registered
FocusListener
objects.
This method is not called unless focus events are enabled for this component. Focus events are enabled when one of the following occurs:
FocusListener
object is registered
via addFocusListener
.
enableEvents
.
If focus events are enabled for a Component
,
the current KeyboardFocusManager
determines
whether or not a focus event should be dispatched to
registered FocusListener
objects. If the
events are to be dispatched, the KeyboardFocusManager
calls the Component
's dispatchEvent
method, which results in a call to the Component
's
processFocusEvent
method.
If focus events are enabled for a Component
, calling
the Component
's dispatchEvent
method
with a FocusEvent
as the argument will result in a
call to the Component
's processFocusEvent
method regardless of the current KeyboardFocusManager
.
Note that if the event parameter is null
the behavior is unspecified and may result in an
exception.
evt | the focus event |
---|
Processes key stroke events such as mnemonics and accelerators.
evt | the key event to be processed |
---|