public class JPopupMenu extends JComponent implements Accessible, MenuElement
| Modifier and Type | Class and Description |
|---|---|
protected class |
JPopupMenu.AccessibleJPopupMenu |
static class |
JPopupMenu.Separator
This is the separator that can be used in popup menu.
|
JComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
protected SingleSelectionModel |
selectionModel
SelectionModel that keeps track of menu selection.
|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWBOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
JPopupMenu()
Creates a new JPopupMenu object.
|
JPopupMenu(String label)
Creates a new JPopupMenu with specified label
|
| Modifier and Type | Method and Description |
|---|---|
JMenuItem |
add(Action action)
Constructs menu item associated with the specified action
and adds it to the popup menu
|
JMenuItem |
add(JMenuItem item)
Adds given menu item to the popup menu
|
JMenuItem |
add(String text)
Constructs menu item with a specified label and adds it to
popup menu
|
void |
addMenuKeyListener(MenuKeyListener l)
Adds a MenuKeyListener to the popup.
|
void |
addPopupMenuListener(PopupMenuListener listener)
Adds popupMenuListener to listen for PopupMenuEvents fired
by the JPopupMenu
|
void |
addSeparator()
Adds separator to this popup menu
|
protected PropertyChangeListener |
createActionChangeListener(JMenuItem item)
Creates PropertyChangeListener that listens to PropertyChangeEvents
occuring in the Action associated with given menu item in this popup menu.
|
protected JMenuItem |
createActionComponent(Action action)
Creates new menu item associated with a given action.
|
protected void |
firePopupMenuCanceled()
This method calls popupMenuCanceled() of popup menu's PopupMenuListeners.
|
protected void |
firePopupMenuWillBecomeInvisible()
This method calls popupMenuWillBecomeInvisible() of popup
menu's PopupMenuListeners.
|
protected void |
firePopupMenuWillBecomeVisible()
This method calls popupMenuWillBecomeVisible() of popup menu's
PopupMenuListeners.
|
AccessibleContext |
getAccessibleContext()
DOCUMENT ME!
|
Component |
getComponent()
Method of the MenuElement interface.
|
Component |
getComponentAtIndex(int index)
Deprecated.
Replaced by getComponent(int)
|
int |
getComponentIndex(Component component)
Returns index of the specified component in the popup menu
|
static boolean |
getDefaultLightWeightPopupEnabled()
Returns flag indicating if newly created JPopupMenu will use
heavyweight or lightweight container to display its menu items
|
Component |
getInvoker()
Returns popup menu's invoker.
|
String |
getLabel()
Returns label for this popup menu
|
Insets |
getMargin()
Returns margin for this popup menu.
|
MenuKeyListener[] |
getMenuKeyListeners()
Returns array of getMenuKeyListeners that are listening to JPopupMenu.
|
PopupMenuListener[] |
getPopupMenuListeners()
Returns array of PopupMenuListeners that are listening to JPopupMenu
|
SingleSelectionModel |
getSelectionModel()
Returns selectionModel used by this popup menu to keep
track of the selection.
|
MenuElement[] |
getSubElements()
Return subcomonents of this popup menu.
|
PopupMenuUI |
getUI()
This method returns the UI used to display the JPopupMenu.
|
String |
getUIClassID()
This method returns a name to identify which look and feel class will be
the UI delegate for the menuItem.
|
void |
insert(Action action,
int index)
Create menu item associated with the given action
and inserts it into the popup menu at the specified index
|
void |
insert(Component component,
int index)
Insert given component to the popup menu at the
specified index
|
boolean |
isBorderPainted()
Checks if this popup menu paints its border.
|
boolean |
isLightWeightPopupEnabled()
Returns true if this popup menu will display its menu item in
a lightweight container and false otherwise.
|
boolean |
isPopupTrigger(MouseEvent event)
Checks if observing mouse event should trigger popup
menu to show on the screen.
|
boolean |
isVisible()
Return visibility of the popup menu
|
void |
menuSelectionChanged(boolean changed)
Method of MenuElement Interface.
|
void |
pack()
This methods sets popup menu's size to its' preferred size.
|
protected String |
paramString()
A string that describes this JPopupMenu.
|
void |
processKeyEvent(KeyEvent event,
MenuElement[] path,
MenuSelectionManager manager)
Process key events forwarded from MenuSelectionManager.
|
void |
processMouseEvent(MouseEvent event,
MenuElement[] path,
MenuSelectionManager manager)
Process mouse events forwarded from MenuSelectionManager.
|
void |
remove(int index)
Revomes component at the given index from the menu.
|
void |
removeMenuKeyListener(MenuKeyListener l)
Removes a MenuKeyListener from the popup.
|
void |
removePopupMenuListener(PopupMenuListener listener)
Removes PopupMenuListener from JPopupMenu's list of listeners
|
void |
setBorderPainted(boolean painted)
Sets if the border of the popup menu should be
painter or not.
|
static void |
setDefaultLightWeightPopupEnabled(boolean enabled)
Sets whether JPopupMenu should use ligthWeight container to
display it menu items by default
|
void |
setInvoker(Component component)
Sets popup menu's invoker.
|
void |
setLabel(String label)
Sets label for this popup menu.
|
void |
setLightWeightPopupEnabled(boolean enabled)
DOCUMENT ME!
|
void |
setLocation(int x,
int y)
Sets location of the popup menu.
|
void |
setPopupSize(Dimension size)
Sets size of the popup
|
void |
setPopupSize(int width,
int height)
Sets size of the popup menu
|
void |
setSelected(Component selected)
Selects specified component in this popup menu.
|
void |
setSelectionModel(SingleSelectionModel model)
Sets selection model for this popup menu
|
void |
setUI(PopupMenuUI ui)
Set the "UI" property of the menu item, which is a look and feel class
responsible for handling popupMenu's input events and painting it.
|
void |
setVisible(boolean visible)
Sets visibility property of this popup menu.
|
void |
show(Component component,
int x,
int y)
This method displays JPopupMenu on the screen at the specified
location.
|
void |
updateUI()
This method sets this menuItem's UI to the UIManager's default for the
current look and feel.
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, unregisterKeyboardAction, updateadd, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeaction, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, 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, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleprotected SingleSelectionModel selectionModel
public JPopupMenu()
public JPopupMenu(String label)
label - Label for popup menu.public JMenuItem add(JMenuItem item)
item - menu item to add to the popup menupublic JMenuItem add(String text)
text - label for the menu item to be addedpublic JMenuItem add(Action action)
action - Action for the new menu itempublic void remove(int index)
public void insert(Action action, int index)
action - Action for the new menu itemindex - index in the popup menu at which to insert new menu item.public void insert(Component component, int index)
component - Component to insertindex - Index at which to insert given componentpublic static boolean getDefaultLightWeightPopupEnabled()
public static void setDefaultLightWeightPopupEnabled(boolean enabled)
enabled - true if JPopupMenu should use lightweight container
for displaying its menu items, and false otherwise.public PopupMenuUI getUI()
public void setUI(PopupMenuUI ui)
ui - The new "UI" propertypublic void updateUI()
updateUI in class JComponentpublic String getUIClassID()
getUIClassID in class JComponentJComponent.setUI(javax.swing.plaf.ComponentUI),
JComponent.updateUI()public SingleSelectionModel getSelectionModel()
public void setSelectionModel(SingleSelectionModel model)
model - new selection model of this popup menuprotected JMenuItem createActionComponent(Action action)
action - Action used to create new menu itemprotected PropertyChangeListener createActionChangeListener(JMenuItem item)
item - MenuItempublic boolean isLightWeightPopupEnabled()
public void setLightWeightPopupEnabled(boolean enabled)
enabled - DOCUMENT ME!public String getLabel()
public void setLabel(String label)
label - label for this popup menupublic void addSeparator()
public void addMenuKeyListener(MenuKeyListener l)
l - - the listener to add.public void removeMenuKeyListener(MenuKeyListener l)
l - - the listener to remove.public MenuKeyListener[] getMenuKeyListeners()
public void addPopupMenuListener(PopupMenuListener listener)
listener - PopupMenuListener to add to JPopupMenupublic void removePopupMenuListener(PopupMenuListener listener)
listener - PopupMenuListener which needs to be removedpublic PopupMenuListener[] getPopupMenuListeners()
protected void firePopupMenuWillBecomeVisible()
protected void firePopupMenuWillBecomeInvisible()
protected void firePopupMenuCanceled()
public void pack()
public boolean isVisible()
isVisible in class ComponentComponent.setVisible(boolean)public void setVisible(boolean visible)
setVisible in class JComponentvisible - true if popup menu will become visible and false otherwise.Component.isVisible()public void setLocation(int x, int y)
setLocation in class Componentx - X coordinate of the popup menu's locationy - Y coordinate of the popup menu's locationComponent.getLocation(),
Component.setBounds(int, int, int, int)public Component getInvoker()
public void setInvoker(Component component)
component - The new invoker of this popup menupublic void show(Component component, int x, int y)
component - Invoker for this popup menux - x-coordinate of the popup menu relative to the specified invokery - y-coordiate of the popup menu relative to the specified invokerpublic Component getComponentAtIndex(int index)
index - index of the component to returnpublic int getComponentIndex(Component component)
component - Component to look forpublic void setPopupSize(Dimension size)
size - Dimensions representing new size of the popup menupublic void setPopupSize(int width, int height)
width - width for the new sizeheight - height for the new sizepublic void setSelected(Component selected)
selected - component to selectpublic boolean isBorderPainted()
public void setBorderPainted(boolean painted)
painted - true if the border should be painted and false otherwisepublic Insets getMargin()
protected String paramString()
paramString in class JComponentpublic void processMouseEvent(MouseEvent event, MenuElement[] path, MenuSelectionManager manager)
processMouseEvent in interface MenuElementevent - event forwarded from MenuSelectionManagerpath - path to the menu element from which event was generatedmanager - MenuSelectionManager for the current menu hierarchypublic void processKeyEvent(KeyEvent event, MenuElement[] path, MenuSelectionManager manager)
processKeyEvent in interface MenuElementevent - event forwarded from MenuSelectionManagerpath - path to the menu element from which event was generatedmanager - MenuSelectionManager for the current menu hierarchypublic void menuSelectionChanged(boolean changed)
menuSelectionChanged in interface MenuElementchanged - true if this popupMenu is part of current menu
hierarchy and false otherwise.public MenuElement[] getSubElements()
MenuElement interface.getSubElements in interface MenuElementpublic Component getComponent()
getComponent in interface MenuElementpublic boolean isPopupTrigger(MouseEvent event)
event - MouseEvent to checkpublic AccessibleContext getAccessibleContext()
getAccessibleContext in interface AccessiblegetAccessibleContext in class JComponent