Package Summary  Overview Summary

class:JPopupMenu [NONE]

  • All Implemented Interfaces:
    ImageObserver, MenuContainer, Serializable, Accessible, MenuElement
    Direct Known Subclasses:
    BasicComboPopup

    @JavaBean(defaultProperty="UI",
              description="A small window that pops up and displays a series of choices.")
    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.

    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 JavaBeans™ has been added to the java.beans package. Please see XMLEncoder.

    Since:
    1.2
    See Also:
    Serialized Form

constructor:<init>() [NONE]

  • JPopupMenu

    public JPopupMenu()
    Constructs a JPopupMenu without an "invoker".

constructor:<init>(java.lang.String) [NONE]

  • JPopupMenu

    public JPopupMenu​(String label)
    Constructs a JPopupMenu with the specified title.
    Parameters:
    label - the string that a UI may use to display as a title for the popup menu.

method:setDefaultLightWeightPopupEnabled(boolean) [NONE]

method:getDefaultLightWeightPopupEnabled() [NONE]

  • getDefaultLightWeightPopupEnabled

    public static boolean getDefaultLightWeightPopupEnabled()
    Gets the defaultLightWeightPopupEnabled property, which by default is true.
    Returns:
    the value of the defaultLightWeightPopupEnabled property
    See Also:
    setDefaultLightWeightPopupEnabled(boolean)

method:getUI() [NONE]

  • getUI

    public PopupMenuUI getUI()
    Returns the look and feel (L&F) object that renders this component.
    Overrides:
    getUI in class JComponent
    Returns:
    the PopupMenuUI object that renders this component

method:setUI(javax.swing.plaf.PopupMenuUI) [NONE]

method:updateUI() [NONE]

method:getUIClassID() [NONE]

method:processFocusEvent(java.awt.event.FocusEvent) [NONE]

  • processFocusEvent

    protected void processFocusEvent​(FocusEvent evt)
    Description copied from class: Component
    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:

    • A FocusListener object is registered via addFocusListener.
    • Focus events are enabled via 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.

    Overrides:
    processFocusEvent in class Component
    Parameters:
    evt - the focus event
    See Also:
    FocusEvent, FocusListener, KeyboardFocusManager, Component.addFocusListener(java.awt.event.FocusListener), Component.enableEvents(long), Component.dispatchEvent(java.awt.AWTEvent)

method:processKeyEvent(java.awt.event.KeyEvent) [NONE]

method:getSelectionModel() [NONE]

method:setSelectionModel(javax.swing.SingleSelectionModel) [NONE]

method:add(javax.swing.JMenuItem) [NONE]

  • add

    public JMenuItem add​(JMenuItem menuItem)
    Appends the specified menu item to the end of this menu.
    Parameters:
    menuItem - the JMenuItem to add
    Returns:
    the JMenuItem added

method:add(java.lang.String) [NONE]

  • add

    public JMenuItem add​(String s)
    Creates a new menu item with the specified text and appends it to the end of this menu.
    Parameters:
    s - the string for the menu item to be added
    Returns:
    a new JMenuItem created using s

method:add(javax.swing.Action) [NONE]

  • add

    public JMenuItem add​(Action a)
    Appends a new menu item to the end of the menu which dispatches the specified Action object.
    Parameters:
    a - the Action to add to the menu
    Returns:
    the new menu item
    See Also:
    Action

method:createActionComponent(javax.swing.Action) [NONE]

  • createActionComponent

    protected JMenuItem createActionComponent​(Action a)
    Factory method which creates the JMenuItem for Actions added to the JPopupMenu.
    Parameters:
    a - the Action for the menu item to be added
    Returns:
    the new menu item
    Since:
    1.3
    See Also:
    Action

method:createActionChangeListener(javax.swing.JMenuItem) [NONE]

  • createActionChangeListener

    protected PropertyChangeListener createActionChangeListener​(JMenuItem b)
    Returns a properly configured PropertyChangeListener which updates the control as changes to the Action occur.
    Parameters:
    b - the menu item for which to create a listener
    Returns:
    a properly configured PropertyChangeListener

method:remove(int) [NONE]

method:setLightWeightPopupEnabled(boolean) [NONE]

  • setLightWeightPopupEnabled

    @BeanProperty(bound=false,
                  expert=true,
                  description="Determines whether lightweight popups are used when possible")
    public void setLightWeightPopupEnabled​(boolean aFlag)
    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.
    Parameters:
    aFlag - false to disable lightweight popups
    See Also:
    isLightWeightPopupEnabled()

method:isLightWeightPopupEnabled() [NONE]

  • isLightWeightPopupEnabled

    public boolean isLightWeightPopupEnabled()
    Gets the lightWeightPopupEnabled property.
    Returns:
    the value of the lightWeightPopupEnabled property
    See Also:
    setLightWeightPopupEnabled(boolean)

method:getLabel() [NONE]

method:setLabel(java.lang.String) [NONE]

  • setLabel

    @BeanProperty(description="The label for the popup menu.")
    public void setLabel​(String label)
    Sets the popup menu's label. Different look and feels may choose to display or not display this.
    Parameters:
    label - a string specifying the label for the popup menu
    See Also:
    setLabel(java.lang.String)

method:addSeparator() [NONE]

  • addSeparator

    public void addSeparator()
    Appends a new separator at the end of the menu.

method:insert(javax.swing.Action,int) [NONE]

  • insert

    public void insert​(Action a,
                       int index)
    Inserts a menu item for the specified Action object at a given position.
    Parameters:
    a - the Action object to insert
    index - specifies the position at which to insert the Action, where 0 is the first
    Throws:
    IllegalArgumentException - if index < 0
    See Also:
    Action

method:insert(java.awt.Component,int) [NONE]

  • insert

    public void insert​(Component component,
                       int index)
    Inserts the specified component into the menu at a given position.
    Parameters:
    component - the Component to insert
    index - specifies the position at which to insert the component, where 0 is the first
    Throws:
    IllegalArgumentException - if index < 0

method:addPopupMenuListener(javax.swing.event.PopupMenuListener) [NONE]

  • addPopupMenuListener

    public void addPopupMenuListener​(PopupMenuListener l)
    Adds a PopupMenu listener.
    Parameters:
    l - the PopupMenuListener to add

method:removePopupMenuListener(javax.swing.event.PopupMenuListener) [NONE]

  • removePopupMenuListener

    public void removePopupMenuListener​(PopupMenuListener l)
    Removes a PopupMenu listener.
    Parameters:
    l - the PopupMenuListener to remove

method:getPopupMenuListeners() [NONE]

  • getPopupMenuListeners

    @BeanProperty(bound=false)
    public PopupMenuListener[] getPopupMenuListeners()
    Returns an array of all the PopupMenuListeners added to this JMenuItem with addPopupMenuListener().
    Returns:
    all of the PopupMenuListeners added or an empty array if no listeners have been added
    Since:
    1.4

method:addMenuKeyListener(javax.swing.event.MenuKeyListener) [NONE]

  • addMenuKeyListener

    public void addMenuKeyListener​(MenuKeyListener l)
    Adds a MenuKeyListener to the popup menu.
    Parameters:
    l - the MenuKeyListener to be added
    Since:
    1.5

method:removeMenuKeyListener(javax.swing.event.MenuKeyListener) [NONE]

  • removeMenuKeyListener

    public void removeMenuKeyListener​(MenuKeyListener l)
    Removes a MenuKeyListener from the popup menu.
    Parameters:
    l - the MenuKeyListener to be removed
    Since:
    1.5

method:getMenuKeyListeners() [NONE]

  • getMenuKeyListeners

    @BeanProperty(bound=false)
    public MenuKeyListener[] getMenuKeyListeners()
    Returns an array of all the MenuKeyListeners added to this JPopupMenu with addMenuKeyListener().
    Returns:
    all of the MenuKeyListeners added or an empty array if no listeners have been added
    Since:
    1.5

method:firePopupMenuWillBecomeVisible() [NONE]

  • firePopupMenuWillBecomeVisible

    protected void firePopupMenuWillBecomeVisible()
    Notifies PopupMenuListeners that this popup menu will become visible.

method:firePopupMenuWillBecomeInvisible() [NONE]

  • firePopupMenuWillBecomeInvisible

    protected void firePopupMenuWillBecomeInvisible()
    Notifies PopupMenuListeners that this popup menu will become invisible.

method:firePopupMenuCanceled() [NONE]

  • firePopupMenuCanceled

    protected void firePopupMenuCanceled()
    Notifies PopupMenuListeners that this popup menu is cancelled.

method:pack() [NONE]

  • pack

    public void pack()
    Lays out the container so that it uses the minimum space needed to display its contents.

method:setVisible(boolean) [NONE]

method:isVisible() [NONE]

  • isVisible

    public boolean isVisible()
    Returns true if the popup menu is visible (currently being displayed).
    Overrides:
    isVisible in class Component
    Returns:
    true if the component is visible, false otherwise
    See Also:
    Component.setVisible(boolean)

method:setLocation(int,int) [NONE]

  • setLocation

    @BeanProperty(description="The location of the popup menu.")
    public void setLocation​(int x,
                            int y)
    Sets the location of the upper left corner of the popup menu using x, y coordinates.

    The method changes the geometry-related data. Therefore, the native windowing system may ignore such requests, or it may modify the requested data, so that the JPopupMenu object is placed and sized in a way that corresponds closely to the desktop settings.

    Overrides:
    setLocation in class Component
    Parameters:
    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
    See Also:
    Component.getLocation(), Component.setBounds(int, int, int, int) , Component.invalidate()

method:getInvoker() [NONE]

  • getInvoker

    public Component getInvoker()
    Returns the component which is the 'invoker' of this popup menu.
    Returns:
    the Component in which the popup menu is displayed

method:setInvoker(java.awt.Component) [NONE]

  • setInvoker

    @BeanProperty(bound=false,
                  expert=true,
                  description="The invoking component for the popup menu")
    public void setInvoker​(Component invoker)
    Sets the invoker of this popup menu -- the component in which the popup menu menu is to be displayed.
    Parameters:
    invoker - the Component in which the popup menu is displayed

method:show(java.awt.Component,int,int) [NONE]

  • show

    public 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.
    Parameters:
    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

method:getComponentAtIndex(int) [NONE]

  • getComponentAtIndex

    @Deprecated
    public Component getComponentAtIndex​(int i)
    Deprecated.
    Returns the component at the specified index.
    Parameters:
    i - the index of the component, where 0 is the first
    Returns:
    the Component at that index

method:getComponentIndex(java.awt.Component) [NONE]

  • getComponentIndex

    public int getComponentIndex​(Component c)
    Returns the index of the specified component.
    Parameters:
    c - the Component to find
    Returns:
    the index of the component, where 0 is the first; or -1 if the component is not found

method:setPopupSize(java.awt.Dimension) [NONE]

  • setPopupSize

    @BeanProperty(description="The size of the popup menu")
    public void setPopupSize​(Dimension d)
    Sets the size of the Popup window using a Dimension object. This is equivalent to setPreferredSize(d).
    Parameters:
    d - the Dimension specifying the new size of this component.

method:setPopupSize(int,int) [NONE]

  • setPopupSize

    @BeanProperty(description="The size of the popup menu")
    public void setPopupSize​(int width,
                             int height)
    Sets the size of the Popup window to the specified width and height. This is equivalent to setPreferredSize(new Dimension(width, height)) .
    Parameters:
    width - the new width of the Popup in pixels
    height - the new height of the Popup in pixels

method:setSelected(java.awt.Component) [NONE]

  • setSelected

    @BeanProperty(expert=true,
                  hidden=true,
                  description="The selected component on the popup menu")
    public void setSelected​(Component sel)
    Sets the currently selected component, This will result in a change to the selection model.
    Parameters:
    sel - the Component to select

method:isBorderPainted() [NONE]

  • isBorderPainted

    public boolean isBorderPainted()
    Checks whether the border should be painted.
    Returns:
    true if the border is painted, false otherwise
    See Also:
    setBorderPainted(boolean)

method:setBorderPainted(boolean) [NONE]

  • setBorderPainted

    @BeanProperty(bound=false,
                  description="Is the border of the popup menu painted")
    public void setBorderPainted​(boolean b)
    Sets whether the border should be painted.
    Parameters:
    b - if true, the border is painted.
    See Also:
    isBorderPainted()

method:paintBorder(java.awt.Graphics) [NONE]

method:getMargin() [NONE]

  • getMargin

    @BeanProperty(bound=false)
    public Insets getMargin()
    Returns the margin, in pixels, between the popup menu's border and its containers.
    Returns:
    an Insets object containing the margin values.

method:paramString() [NONE]

  • paramString

    protected String paramString()
    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.
    Overrides:
    paramString in class JComponent
    Returns:
    a string representation of this JPopupMenu.

method:getAccessibleContext() [NONE]

  • getAccessibleContext

    @BeanProperty(bound=false)
    public AccessibleContext getAccessibleContext()
    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.
    Specified by:
    getAccessibleContext in interface Accessible
    Overrides:
    getAccessibleContext in class Component
    Returns:
    an AccessibleJPopupMenu that serves as the AccessibleContext of this JPopupMenu

method:processMouseEvent(java.awt.event.MouseEvent,javax.swing.MenuElement[],javax.swing.MenuSelectionManager) [NONE]

method:processKeyEvent(java.awt.event.KeyEvent,javax.swing.MenuElement[],javax.swing.MenuSelectionManager) [NONE]

  • processKeyEvent

    public void processKeyEvent​(KeyEvent e,
                                MenuElement[] path,
                                MenuSelectionManager manager)
    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.

    Specified by:
    processKeyEvent in interface MenuElement
    Parameters:
    e - a KeyEvent
    path - the MenuElement path array
    manager - the MenuSelectionManager

method:menuSelectionChanged(boolean) [NONE]

  • menuSelectionChanged

    public void menuSelectionChanged​(boolean isIncluded)
    Messaged when the menubar selection changes to activate or deactivate this menu. This implements the javax.swing.MenuElement interface. Overrides MenuElement.menuSelectionChanged.
    Specified by:
    menuSelectionChanged in interface MenuElement
    Parameters:
    isIncluded - true if this menu is active, false if it is not
    See Also:
    MenuElement.menuSelectionChanged(boolean)

method:getSubElements() [NONE]

  • getSubElements

    @BeanProperty(bound=false)
    public MenuElement[] getSubElements()
    Returns an array of MenuElements 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.
    Specified by:
    getSubElements in interface MenuElement
    Returns:
    an array of MenuElement objects
    See Also:
    MenuElement.getSubElements()

method:getComponent() [NONE]

method:isPopupTrigger(java.awt.event.MouseEvent) [NONE]

  • isPopupTrigger

    public boolean isPopupTrigger​(MouseEvent e)
    Returns true if the MouseEvent is considered a popup trigger by the JPopupMenu's currently installed UI.
    Parameters:
    e - a MouseEvent
    Returns:
    true if the mouse event is a popup trigger
    Since:
    1.3

© 2019 Oracle Corporation and/or its affiliates