javax.swing
Class JPopupMenu

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPopupMenu
All Implemented Interfaces:
Accessible, java.awt.image.ImageObserver, MenuContainer, MenuElement, Serializable

public class JPopupMenu
extends JComponent
implements Accessible, MenuElement

Safe:

See Also:
Serialized Form

Field Summary
private static Object classLock
           
private static boolean DEBUG
           
private static Object defaultLWPopupEnabledKey
          Key used in AppContext to determine if light way popups are the default.
private  int desiredLocationX
           
private  int desiredLocationY
           
(package private)  Frame frame
           
(package private)  Component invoker
           
private  String label
           
private  boolean lightWeightPopup
          Used to indicate if lightweight popups should be used.
private  Insets margin
           
private  boolean paintBorder
           
(package private)  Popup popup
           
(package private) static boolean popupPostionFixDisabled
          Bug#4425878-Property javax.swing.adjustPopupLocationToFit introduced
private  SingleSelectionModel selectionModel
           
private static boolean TRACE
           
private static String uiClassID
           
private static boolean VERBOSE
           
 
Fields inherited from class javax.swing.JComponent
_bounds, accessibleContext, listenerList, paintingChild, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
JPopupMenu()
          Enabled: Constructs a JPopupMenu without an "invoker".
JPopupMenu(String label)
          Enabled: Constructs a JPopupMenu with the specified title.
 
Method Summary
 JMenuItem add(Action a)
          Enabled: Appends a new menu item to the end of the menu which dispatches the specified Action object.
 JMenuItem add(JMenuItem menuItem)
          Enabled: Appends the specified menu item to the end of this menu.
 JMenuItem add(String s)
          Enabled: Creates a new menu item with the specified text and appends it to the end of this menu.
 void addPopupMenuListener(PopupMenuListener l)
          Enabled: Adds a PopupMenu listener.
 void addSeparator()
          Enabled: Appends a new separator at the end of the menu.
(package private)  Point adjustPopupLocationToFitScreen(int xposition, int yposition)
          Returns an point which has been adjusted to take into account of the desktop bounds, taskbar and multi-monitor configuration.
(package private)  boolean alwaysOnTop()
          Always returns true since popups, by definition, should always be on top of all other windows.
protected  java.beans.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()
          Suppressed: Gets the AccessibleContext associated with this JPopupMenu.
 Component getComponent()
          Enabled: Returns this JPopupMenu component.
 Component getComponentAtIndex(int i)
          Deprecated. replaced by getComponent(int i)
 int getComponentIndex(Component c)
          Enabled: Returns the index of the specified component.
static boolean getDefaultLightWeightPopupEnabled()
          Suppressed: Gets the defaultLightWeightPopupEnabled property, which by default is true.
private static Frame getFrame(Component c)
           
 Component getInvoker()
          Suppressed: Returns the component which is the 'invoker' of this popup menu.
 String getLabel()
          Enabled: Returns the popup menu's label
 Insets getMargin()
          Enabled: Returns the margin, in pixels, between the popup menu's border and its containees.
private  Popup getPopup()
          Returns a Popup instance from the PopupMenuUI that has had show invoked on it.
 PopupMenuListener[] getPopupMenuListeners()
          Suppressed: Returns an array of all the PopupMenuListeners added to this JMenuItem with addPopupMenuListener().
(package private)  JPopupMenu getRootPopupMenu()
          Returns the popup menu which is at the root of the menu system for this popup menu.
 SingleSelectionModel getSelectionModel()
          Enabled: Returns the model object that handles single selections.
 MenuElement[] getSubElements()
          Enabled: Returns an array of MenuElements containing the submenu for this menu component.
 javax.swing.plaf.PopupMenuUI getUI()
          Suppressed: Returns the look and feel (L&F) object that renders this component.
 String getUIClassID()
          Suppressed: Returns the name of the L&F class that renders this component.
 void insert(Action a, int index)
          Enabled: Inserts a menu item for the specified Action object at a given position.
 void insert(Component component, int index)
          Enabled: Inserts the specified component into the menu at a given position.
 boolean isBorderPainted()
          Enabled: Checks whether the border should be painted.
 boolean isLightWeightPopupEnabled()
          Suppressed: Gets the lightWeightPopupEnabled property.
private  boolean isPopupMenu()
          Returns true if the popup menu is a standalone popup menu rather than the submenu of a JMenu.
 boolean isPopupTrigger(MouseEvent e)
          Enabled: Returns true if the MouseEvent is considered a popup trigger by the JPopupMenu's currently installed UI.
(package private)  boolean isSubPopupMenu(JPopupMenu popup)
          Examines the list of menu items to determine whether popup is a popup menu.
 boolean isVisible()
          Enabled: Returns true if the popup menu is visible (currently being displayed).
 void menuSelectionChanged(boolean isIncluded)
          Enabled: Messaged when the menubar selection changes to activate or deactivate this menu.
 void pack()
          Enabled: 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)
          Suppressed: This method is required to conform to the MenuElement interface, but it not implemented.
 void processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager)
          Suppressed: This method is required to conform to the MenuElement interface, but it not implemented.
private  void readObject(ObjectInputStream s)
          We use the ObjectInputStream "registerValidation" callback to update the UI for the entire tree of components after they've all been read in.
 void remove(int pos)
          Enabled: Removes the component at the specified index from this popup menu.
 void removePopupMenuListener(PopupMenuListener l)
          Enabled: Removes a PopupMenu listener.
 void setBorderPainted(boolean b)
          Enabled: Sets whether the border should be painted.
static void setDefaultLightWeightPopupEnabled(boolean aFlag)
          Suppressed: Sets the default value of the lightWeightPopupEnabled property.
 void setInvoker(Component invoker)
          Enabled: Sets the invoker of this popup menu -- the component in which the popup menu menu is to be displayed.
 void setLabel(String label)
          Enabled: Sets the popup menu's label.
 void setLightWeightPopupEnabled(boolean aFlag)
          Suppressed: Sets the value of the lightWeightPopupEnabled property, which by default is true.
 void setLocation(int x, int y)
          Enabled: Sets the location of the upper left corner of the popup menu using x, y coordinates.
 void setPopupSize(Dimension d)
          Enabled: Sets the size of the Popup window using a Dimension object.
 void setPopupSize(int width, int height)
          Enabled: Sets the size of the Popup window to the specified width and height.
 void setSelected(Component sel)
          Enabled: Sets the currently selected component, This will result in a change to the selection model.
 void setSelectionModel(SingleSelectionModel model)
          Enabled: Sets the model object to handle single selections.
 void setUI(javax.swing.plaf.PopupMenuUI ui)
          Suppressed: Sets the L&F object that renders this component.
 void setVisible(boolean b)
          Enabled: Sets the visibility of the popup menu.
 void show(Component invoker, int x, int y)
          Enabled: Displays the popup menu at the position x,y in the coordinate space of the component invoker.
 void updateUI()
          Suppressed: Resets the UI property to a value from the current look and feel.
private  void writeObject(ObjectOutputStream s)
          Before writing a JComponent to an ObjectOutputStream we temporarily uninstall its UI.
 
Methods inherited from class javax.swing.JComponent
_paintImmediately, addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, checkIfChildObscuredBySibling, componentInputMapChanged, computeVisibleRect, computeVisibleRect, compWriteObjectNotify, contains, createToolTip, disable, enable, enableSerialization, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getManagingFocusBackwardTraversalKeys, getManagingFocusForwardTraversalKeys, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getWriteObjCounter, 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, processKeyBindings, processKeyBindingsForAllComponents, processMouseMotionEvent, putClientProperty, rectangleIsObscured, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setWriteObjCounter, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, get, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, iterate, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, size, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setName, setSize, setSize, show, show, toString, transferFocus, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

uiClassID

private static final String uiClassID
See Also:
getUIClassID(), readObject(java.io.ObjectInputStream)

defaultLWPopupEnabledKey

private static final Object defaultLWPopupEnabledKey
Key used in AppContext to determine if light way popups are the default.


popupPostionFixDisabled

static boolean popupPostionFixDisabled
Bug#4425878-Property javax.swing.adjustPopupLocationToFit introduced


invoker

transient Component invoker

popup

transient Popup popup

frame

transient Frame frame

desiredLocationX

private int desiredLocationX

desiredLocationY

private int desiredLocationY

label

private String label

paintBorder

private boolean paintBorder

margin

private Insets margin

lightWeightPopup

private boolean lightWeightPopup
Used to indicate if lightweight popups should be used.


selectionModel

private SingleSelectionModel selectionModel

classLock

private static final Object classLock

TRACE

private static final boolean TRACE

VERBOSE

private static final boolean VERBOSE

DEBUG

private static final boolean DEBUG
Constructor Detail

JPopupMenu

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


JPopupMenu

public JPopupMenu(String label)
Enabled: 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 Detail

setDefaultLightWeightPopupEnabled

public static void setDefaultLightWeightPopupEnabled(boolean aFlag)
Suppressed: Sets the default value of the lightWeightPopupEnabled property.

Parameters:
aFlag - true if popups can be lightweight, otherwise false
See Also:
getDefaultLightWeightPopupEnabled(), setLightWeightPopupEnabled(boolean)

getDefaultLightWeightPopupEnabled

public static boolean getDefaultLightWeightPopupEnabled()
Suppressed: Gets the defaultLightWeightPopupEnabled property, which by default is true.

Returns:
the value of the defaultLightWeightPopupEnabled property
See Also:
setDefaultLightWeightPopupEnabled(boolean)

getUI

public javax.swing.plaf.PopupMenuUI getUI()
Suppressed: Returns the look and feel (L&F) object that renders this component.

Returns:
the PopupMenuUI object that renders this component

setUI

public void setUI(javax.swing.plaf.PopupMenuUI ui)
Suppressed: Sets the L&F object that renders this component.

Parameters:
ui - the new PopupMenuUI L&F object
See Also:
UIDefaults.getUI(javax.swing.JComponent)

updateUI

public void updateUI()
Suppressed: Resets the UI property to a value from the current look and feel.

Overrides:
updateUI in class JComponent
See Also:
JComponent.updateUI()

getUIClassID

public String getUIClassID()
Suppressed: Returns the name of the L&F class that renders this component.

Overrides:
getUIClassID in class JComponent
Returns:
the string "PopupMenuUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

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:

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:
java.awt.event.FocusEvent, java.awt.event.FocusListener, Component.addFocusListener(java.awt.event.FocusListener), Component.enableEvents(long)

processKeyEvent

protected void processKeyEvent(KeyEvent evt)
Processes key stroke events such as mnemonics and accelerators.

Overrides:
processKeyEvent in class JComponent
Parameters:
evt - the key event to be processed
See Also:
java.awt.event.KeyEvent, java.awt.event.KeyListener, Component.addKeyListener(java.awt.event.KeyListener), Component.enableEvents(long), Component.isShowing()

getSelectionModel

public SingleSelectionModel getSelectionModel()
Enabled: Returns the model object that handles single selections.

Returns:
the selectionModel property
See Also:
SingleSelectionModel

setSelectionModel

public void setSelectionModel(SingleSelectionModel model)
Enabled: Sets the model object to handle single selections.

Parameters:
model - the new SingleSelectionModel
See Also:
SingleSelectionModel

add

public JMenuItem add(JMenuItem menuItem)
Enabled: Appends the specified menu item to the end of this menu.

Returns:
the JMenuItem added

add

public JMenuItem add(String s)
Enabled: 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

add

public JMenuItem add(Action a)
Enabled: Appends a new menu item to the end of the menu which dispatches the specified Action object. As of JDK 1.3, this is no longer the preferred method for adding Actions to a container. Instead it is recommended to configure a control with an action using setAction, and then add that control directly to the Container.

Parameters:
a - the Action to add to the menu
Returns:
the new menu item
See Also:
Action

adjustPopupLocationToFitScreen

Point adjustPopupLocationToFitScreen(int xposition,
                                     int yposition)
Returns an point which has been adjusted to take into account of the desktop bounds, taskbar and multi-monitor configuration.

This adustment may be cancelled by invoking the application with -Djavax.swing.adjustPopupLocationToFit=false


createActionComponent

protected JMenuItem createActionComponent(Action a)
Factory method which creates the JMenuItem for Actions added to the JPopupMenu. As of JDK 1.3, this is no longer the preferred method, instead it is recommended to configure a control with an action using setAction, and then adding that control directly to the Container.

Parameters:
a - the Action for the menu item to be added
Returns:
the new menu item
Since:
1.3
See Also:
Action

createActionChangeListener

protected java.beans.PropertyChangeListener createActionChangeListener(JMenuItem b)
Returns a properly configured PropertyChangeListener which updates the control as changes to the Action occur. As of JDK 1.3, this is no longer the preferred method for adding Actions to a container. Instead it is recommended to configure a control with an action using setAction, and then add that control directly to the Container.


remove

public void remove(int pos)
Enabled: Removes the component at the specified index from this popup menu.

Overrides:
remove in class Container
Parameters:
pos - the position of the item to be removed
See Also:
Container.add(java.awt.Component)

setLightWeightPopupEnabled

public void setLightWeightPopupEnabled(boolean aFlag)
Suppressed: 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()

isLightWeightPopupEnabled

public boolean isLightWeightPopupEnabled()
Suppressed: Gets the lightWeightPopupEnabled property.

Returns:
the value of the lightWeightPopupEnabled property
See Also:
setLightWeightPopupEnabled(boolean)

getLabel

public String getLabel()
Enabled: Returns the popup menu's label

Returns:
a string containing the popup menu's label
See Also:
setLabel(java.lang.String)

setLabel

public void setLabel(String label)
Enabled: 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)

addSeparator

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


insert

public void insert(Action a,
                   int index)
Enabled: 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
See Also:
Action

insert

public void insert(Component component,
                   int index)
Enabled: 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

addPopupMenuListener

public void addPopupMenuListener(PopupMenuListener l)
Enabled: Adds a PopupMenu listener.

Parameters:
l - the PopupMenuListener to add

removePopupMenuListener

public void removePopupMenuListener(PopupMenuListener l)
Enabled: Removes a PopupMenu listener.

Parameters:
l - the PopupMenuListener to remove

getPopupMenuListeners

public PopupMenuListener[] getPopupMenuListeners()
Suppressed: 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

firePopupMenuWillBecomeVisible

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


firePopupMenuWillBecomeInvisible

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


firePopupMenuCanceled

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


alwaysOnTop

boolean alwaysOnTop()
Always returns true since popups, by definition, should always be on top of all other windows.

Overrides:
alwaysOnTop in class JComponent
Returns:
true

pack

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


setVisible

public void setVisible(boolean b)
Enabled: Sets the visibility of the popup menu.

Overrides:
setVisible in class JComponent
Parameters:
b - true to make the popup visible, or false to hide it

getPopup

private Popup getPopup()
Returns a Popup instance from the PopupMenuUI that has had show invoked on it. If the current popup is non-null, this will invoke dispose of it, and then show the new one.

This does NOT fire any events, it is up the caller to dispatch the necessary events.


isVisible

public boolean isVisible()
Enabled: 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)

setLocation

public void setLocation(int x,
                        int y)
Enabled: Sets the location of the upper left corner of the popup menu using x, y coordinates.

Overrides:
setLocation in class Component
Parameters:
x - the x coordinate of the popup's new position
y - the y coordinate of the popup's new position
See Also:
Component.getLocation(), Component.setBounds(int, int, int, int)

isPopupMenu

private boolean isPopupMenu()
Returns true if the popup menu is a standalone popup menu rather than the submenu of a JMenu.

Returns:
true if this menu is a standalone popup menu, otherwise false

getInvoker

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

Returns:
the Component in which the popup menu is displayed

setInvoker

public void setInvoker(Component invoker)
Enabled: 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

show

public void show(Component invoker,
                 int x,
                 int y)
Enabled: 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

getRootPopupMenu

JPopupMenu getRootPopupMenu()
Returns the popup menu which is at the root of the menu system for this popup menu.

Returns:
the topmost grandparent JPopupMenu

getComponentAtIndex

public Component getComponentAtIndex(int i)
Deprecated. replaced by getComponent(int i)

Enabled: 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

getComponentIndex

public int getComponentIndex(Component c)
Enabled: Returns the index of the specified component.

Returns:
the index of the component, where 0 is the first; or -1 if the component is not found

setPopupSize

public void setPopupSize(Dimension d)
Enabled: 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.

setPopupSize

public void setPopupSize(int width,
                         int height)
Enabled: Sets the size of the Popup window to the specified width and height. This is equivalent to setPreferredSize(new Dimension(width, height)).


setSelected

public void setSelected(Component sel)
Enabled: Sets the currently selected component, This will result in a change to the selection model.

Parameters:
sel - the Component to select

isBorderPainted

public boolean isBorderPainted()
Enabled: Checks whether the border should be painted.

Returns:
true if the border is painted, false otherwise
See Also:
setBorderPainted(boolean)

setBorderPainted

public void setBorderPainted(boolean b)
Enabled: Sets whether the border should be painted.

Parameters:
b - if true, the border is painted.
See Also:
isBorderPainted()

paintBorder

protected void paintBorder(Graphics g)
Paints the popup menu's border if the borderPainted property is true.

Overrides:
paintBorder in class JComponent
Parameters:
g - the Graphics object
See Also:
JComponent.paint(java.awt.Graphics), JComponent.setBorder(javax.swing.border.Border)

getMargin

public Insets getMargin()
Enabled: Returns the margin, in pixels, between the popup menu's border and its containees.

Returns:
an Insets object containing the margin values.

isSubPopupMenu

boolean isSubPopupMenu(JPopupMenu popup)
Examines the list of menu items to determine whether popup is a popup menu.

Parameters:
popup - a JPopupMenu
Returns:
true if popup

getFrame

private static Frame getFrame(Component c)

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.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Suppressed: 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 JComponent
Returns:
an AccessibleJPopupMenu that serves as the AccessibleContext of this JPopupMenu

writeObject

private void writeObject(ObjectOutputStream s)
                  throws IOException
Description copied from class: JComponent
Before writing a JComponent to an ObjectOutputStream we temporarily uninstall its UI. This is tricky to do because we want to uninstall the UI before any of the JComponent's children (or its LayoutManager etc.) are written, and we don't want to restore the UI until the most derived JComponent subclass has been been stored.

Parameters:
s - the ObjectOutputStream in which to write
IOException

readObject

private void readObject(ObjectInputStream s)
                 throws IOException,
                        ClassNotFoundException
Description copied from class: JComponent
We use the ObjectInputStream "registerValidation" callback to update the UI for the entire tree of components after they've all been read in.

Parameters:
s - the ObjectInputStream from which to read
IOException
ClassNotFoundException
See Also:
ReadObjectCallback

processMouseEvent

public void processMouseEvent(MouseEvent event,
                              MenuElement[] path,
                              MenuSelectionManager manager)
Suppressed: This method is required to conform to the MenuElement interface, but it not implemented.

Specified by:
processMouseEvent in interface MenuElement
See Also:
MenuElement.processMouseEvent(MouseEvent, MenuElement[], MenuSelectionManager)

processKeyEvent

public void processKeyEvent(KeyEvent e,
                            MenuElement[] path,
                            MenuSelectionManager manager)
Suppressed: This method is required to conform to the MenuElement interface, but it not implemented.

Specified by:
processKeyEvent in interface MenuElement
See Also:
MenuElement.processKeyEvent(KeyEvent, MenuElement[], MenuSelectionManager)

menuSelectionChanged

public void menuSelectionChanged(boolean isIncluded)
Enabled: 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)

getSubElements

public MenuElement[] getSubElements()
Enabled: 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()

getComponent

public Component getComponent()
Enabled: Returns this JPopupMenu component.

Specified by:
getComponent in interface MenuElement
Returns:
this JPopupMenu object
See Also:
MenuElement.getComponent()

isPopupTrigger

public boolean isPopupTrigger(MouseEvent e)
Enabled: Returns true if the MouseEvent is considered a popup trigger by the JPopupMenu's currently installed UI.

Returns:
true if the mouse event is a popup trigger
Since:
1.3


comments?