javax.swing
Class JPopupMenu

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPopupMenu
All Implemented Interfaces:
Accessible, ImageObserver, MenuContainer, MenuElement, Serializable
Direct Known Subclasses:
BasicComboPopup
public class JPopupMenu
extends JComponent
implements Accessible, MenuElement

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. For the keyboard keys used by this component in the standard Look and Feel (L&F) renditions, see the JPopupMenu key assignments.

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 Class Summary

protected  class JPopupMenu.AccessibleJPopupMenu
    This class implements accessibility support for the JPopupMenu class.
static class JPopupMenu.Separator
    A popup menu-specific separator.
 
Nested classes inherited from class javax.swing.JComponent
 
Nested classes inherited from class java.awt.Container
 
Nested classes inherited from class java.awt.Component
Component.BltBufferStrategy, Component.FlipBufferStrategy
 

 

Field Summary

 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 

 

Constructor Summary

JPopupMenu()
    Constructs a JPopupMenu without an "invoker".
JPopupMenu(String label)
    Constructs a JPopupMenu with the specified title.
 

 

Method Summary

 JMenuItem add(Action a)
    Appends a new menu item to the end of the menu which dispatches the specified Action object.
 JMenuItem add(JMenuItem menuItem)
    Appends the specified menu item to the end of this menu.
 JMenuItem add(String s)
    Creates a new menu item with the specified text and appends it to the end of this menu.
 void addPopupMenuListener(PopupMenuListener l)
    Adds a PopupMenu listener.
 void addSeparator()
    Appends a new separator at the end of the menu.
protected  PropertyChangeListener createActionChangeListener(JMenuItem b)
    Returns a properly configured PropertyChangeListener which updates the control as changes to the Action occur.
protected  JMenuItem createActionComponent(Action a)
    Factory method which creates the JMenuItem for Actions added to the JPopupMenu.
protected  void firePopupMenuCanceled()
    Notifies PopupMenuListeners that this popup menu is cancelled.
protected  void firePopupMenuWillBecomeInvisible()
    Notifies PopupMenuListeners that this popup menu will become invisible.
protected  void firePopupMenuWillBecomeVisible()
    Notifies PopupMenuListeners that this popup menu will become visible.
 AccessibleContext getAccessibleContext()
    Gets the AccessibleContext associated with this JPopupMenu.
 Component getComponent()
    Returns this JPopupMenu component.
 Component getComponentAtIndex(int i)
    Deprecated. replaced by getComponent(int i)
 int getComponentIndex(Component c)
    Returns the index of the specified component.
static boolean getDefaultLightWeightPopupEnabled()
    Gets the defaultLightWeightPopupEnabled property, which by default is true.
 Component getInvoker()
    Returns the component which is the 'invoker' of this popup menu.
 String getLabel()
    Returns the popup menu's label
 Insets getMargin()
    Returns the margin, in pixels, between the popup menu's border and its containees.
 PopupMenuListener[] getPopupMenuListeners()
    Returns an array of all the PopupMenuListeners added to this JMenuItem with addPopupMenuListener().
 SingleSelectionModel getSelectionModel()
    Returns the model object that handles single selections.
 MenuElement[] getSubElements()
    Returns an array of MenuElements containing the submenu for this menu component.
 PopupMenuUI getUI()
    Returns the look and feel (L&F) object that renders this component.
 String getUIClassID()
    Returns the name of the L&F class that renders this component.
 void insert(Action a, int index)
    Inserts a menu item for the specified Action object at a given position.
 void insert(Component component, int index)
    Inserts the specified component into the menu at a given position.
 boolean isBorderPainted()
    Checks whether the border should be painted.
 boolean isLightWeightPopupEnabled()
    Gets the lightWeightPopupEnabled property.
 boolean isPopupTrigger(MouseEvent e)
    Returns true if the MouseEvent is considered a popup trigger by the JPopupMenu's currently installed UI.
 boolean isVisible()
    Returns true if the popup menu is visible (currently being displayed).
 void menuSelectionChanged(boolean isIncluded)
    Messaged when the menubar selection changes to activate or deactivate this menu.
 void pack()
    Lays out the container so that it uses the minimum space needed to display its contents.
protected  void paintBorder(Graphics g)
    Paints the popup menu's border if the borderPainted property is true.
protected  String paramString()
    Returns a string representation of this JPopupMenu.
protected  void processFocusEvent(FocusEvent evt)
    Processes focus events occurring on this component by dispatching them to any registered FocusListener objects.
protected  void processKeyEvent(KeyEvent evt)
    Processes key stroke events such as mnemonics and accelerators.
 void processKeyEvent(KeyEvent e, MenuElement[] path, MenuSelectionManager manager)
    This method is required to conform to the MenuElement interface, but it not implemented.
 void processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager)
    This method is required to conform to the MenuElement interface, but it not implemented.
 void remove(int pos)
    Removes the component at the specified index from this popup menu.
 void removePopupMenuListener(PopupMenuListener l)
    Removes a PopupMenu listener.
 void setBorderPainted(boolean b)
    Sets whether the border should be painted.
static void setDefaultLightWeightPopupEnabled(boolean aFlag)
    Sets the default value of the lightWeightPopupEnabled property.
 void setInvoker(Component invoker)
    Sets the invoker of this popup menu -- the component in which the popup menu menu is to be displayed.
 void setLabel(String label)
    Sets the popup menu's label.
 void setLightWeightPopupEnabled(boolean aFlag)
    Sets the value of the lightWeightPopupEnabled property, which by default is true.
 void setLocation(int x, int y)
    Sets the location of the upper left corner of the popup menu using x, y coordinates.
 void setPopupSize(Dimension d)
    Sets the size of the Popup window using a Dimension object.
 void setPopupSize(int width, int height)
    Sets the size of the Popup window to the specified width and height.
 void setSelected(Component sel)
    Sets the currently selected component, This will result in a change to the selection model.
 void setSelectionModel(SingleSelectionModel model)
    Sets the model object to handle single selections.
 void setUI(PopupMenuUI ui)
    Sets the L&F object that renders this component.
 void setVisible(boolean b)
    Sets the visibility of the popup menu.
 void show(Component invoker, int x, int y)
    Displays the popup menu at the position x,y in the coordinate space of the component invoker.
 void updateUI()
    Resets the UI property to a value from the current look and feel.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNe