This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.


javax.swing
class JMenu

java.lang.Object extended by java.awt.Component extended by java.awt.Container extended by javax.swing.JComponent extended by javax.swing.AbstractButton extended by javax.swing.JMenuItem extended by javax.swing.JMenu
All Implemented Interfaces:
ItemSelectable, MenuContainer, ImageObserver, Serializable, Accessible, MenuElement, SwingConstants, TransferHandler.HasGetTransferHandler

Most common way to construct:

JMenu menu = new JMenu("File");

Based on 173 examples


public class JMenu
extends JMenuItem
implements Accessible, MenuElement

An implementation of a menu -- a popup window containing JMenuItems that is displayed when the user selects an item on the JMenuBar. In addition to JMenuItems, a JMenu can also contain JSeparators.

In essence, a menu is a button with an associated JPopupMenu. When the "button" is pressed, the JPopupMenu appears. If the "button" is on the JMenuBar, the menu is a top-level window. If the "button" is another menu item, then the JPopupMenu is "pull-right" menu.

Menus can be configured, and to some degree controlled, by Actions. Using an Action with a menu has many benefits beyond directly configuring a menu. Refer to Swing Components Supporting Action for more details, and you can find more information in How to Use Actions, a section in The Java Tutorial.

For information and examples of using menus see How to Use Menus, a section 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 {@link java.beans.XMLEncoder}.


Nested Class Summary
protected class

           This class implements accessibility support for the JMenu class.
protected class

           A listener class that watches for a popup window closing.
Nested classes/interfaces inherited from class javax.swing.JMenuItem
JMenuItem.AccessibleJMenuItem
 
Nested classes/interfaces inherited from class javax.swing.AbstractButton
AbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListener
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
   
Field Summary
protected JMenu.WinListener popupListener
          The window-closing listener for the popup.
 
Fields inherited from class javax.swing.AbstractButton
actionListener, BORDER_PAINTED_CHANGED_PROPERTY, changeEvent, changeListener, CONTENT_AREA_FILLED_CHANGED_PROPERTY, DISABLED_ICON_CHANGED_PROPERTY, DISABLED_SELECTED_ICON_CHANGED_PROPERTY, FOCUS_PAINTED_CHANGED_PROPERTY, HORIZONTAL_ALIGNMENT_CHANGED_PROPERTY, HORIZONTAL_TEXT_POSITION_CHANGED_PROPERTY, ICON_CHANGED_PROPERTY, itemListener, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, model, MODEL_CHANGED_PROPERTY, PRESSED_ICON_CHANGED_PROPERTY, ROLLOVER_ENABLED_CHANGED_PROPERTY, ROLLOVER_ICON_CHANGED_PROPERTY, ROLLOVER_SELECTED_ICON_CHANGED_PROPERTY, SELECTED_ICON_CHANGED_PROPERTY, TEXT_CHANGED_PROPERTY, VERTICAL_ALIGNMENT_CHANGED_PROPERTY, VERTICAL_TEXT_POSITION_CHANGED_PROPERTY
 
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
 
Constructor Summary

          Constructs a new JMenu with no text.

          Constructs a menu whose properties are taken from the Action supplied.

          Constructs a new JMenu with the supplied string as its text.
JMenu(String s, boolean b)

          Constructs a new JMenu with the supplied string as its text and specified as a tear-off menu or not.
 
Method Summary
 JMenuItem

          Creates a new menu item attached to the specified Action object and appends it to the end of this menu.
 Component

          Appends a component to the end of this menu.
 Component
add(Component c, int index)

          Adds the specified component to this container at the given position.
 JMenuItem
add(JMenuItem menuItem)

          Appends a menu item to the end of this menu.
 JMenuItem

          Creates a new menu item with the specified text and appends it to the end of this menu.
 void

          Adds a listener for menu events.
 void

          Appends a new separator to the end of the menu.
 void

          Sets the ComponentOrientation property of this menu and all components contained within it.
protected PropertyChangeListener

          Returns a properly configured PropertyChangeListener which updates the control as changes to the Action occur.
protected JMenuItem

          Factory method which creates the JMenuItem for Actions added to the JMenu.
protected JMenu.WinListener

          Creates a window-closing listener for the popup.
 void
doClick(int pressTime)

          Programmatically performs a "click".
protected void

          Notifies all listeners that have registered interest for notification on this event type.
protected void

          Notifies all listeners that have registered interest for notification on this event type.
protected void

          Notifies all listeners that have registered interest for notification on this event type.
 AccessibleContext

          Gets the AccessibleContext associated with this JMenu.
 Component

          Returns the java.awt.Component used to paint this MenuElement.
 int

          Returns the suggested delay, in milliseconds, before submenus are popped up or down.
 JMenuItem
getItem(int pos)

          Returns the JMenuItem at the specified position.
 int

          Returns the number of items on the menu, including separators.
 Component

          Returns the component at position n.
 int

          Returns the number of components on the menu.
 Component[]

          Returns an array of Components of the menu's subcomponents.
 MenuListener[]

          Returns an array of all the MenuListeners added to this JMenu with addMenuListener().
 JPopupMenu

          Returns the popupmenu associated with this menu.
protected Point

          Computes the origin for the JMenu's popup menu.
 MenuElement[]

          Returns an array of MenuElements containing the submenu for this menu component.
 String

          Returns the name of the L&F class that renders this component.
 JMenuItem
insert(Action a, int pos)

          Inserts a new menu item attached to the specified Action object at a given position.
 JMenuItem
insert(JMenuItem mi, int pos)

          Inserts the specified JMenuitem at a given position.
 void
insert(String s, int pos)

          Inserts a new menu item with the specified text at a given position.
 void
insertSeparator(int index)

          Inserts a separator at the specified position.
 boolean

          Returns true if the specified component exists in the submenu hierarchy.
 boolean

          Returns true if the menu's popup window is visible.
 boolean

          Returns true if the menu is currently selected (highlighted).
 boolean

          Returns true if the menu can be torn off.
 boolean

          Returns true if the menu is a 'top-level menu', that is, if it is the direct child of a menubar.
 void
menuSelectionChanged(boolean isIncluded)

          Messaged when the menubar selection changes to activate or deactivate this menu.
protected String

          Returns a string representation of this JMenu.
protected void

          Processes key stroke events such as mnemonics and accelerators.
 void

          Removes the component c from this menu.
 void
remove(int pos)

          Removes the menu item at the specified index from this menu.
 void

          Removes the specified menu item from this menu.
 void

          Removes all menu items from this menu.
 void

          Removes a listener for menu events.
 void

          setAccelerator is not defined for JMenu.
 void

          Sets the language-sensitive orientation that is to be used to order the elements or text within this component.
 void
setDelay(int d)

          Sets the suggested delay before the menu's PopupMenu is popped up or down.
 void
setMenuLocation(int x, int y)

          Sets the location of the popup component.
 void

          Sets the data model for the "menu button" -- the label that the user clicks to open or close the menu.
 void

          Sets the visibility of the menu's popup.
 void
setSelected(boolean b)

          Sets the selection status of the menu.
 void

          Resets the UI property with a value from the current look and feel.
 
Methods inherited from class javax.swing.JMenuItem
actionPropertyChanged, addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, getAccessibleContext, getComponent, getMenuDragMouseListeners, getMenuKeyListeners, getSubElements, getUIClassID, init, isArmed, menuSelectionChanged, paramString, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setAccelerator, setArmed, setEnabled, setModel, setUI, updateUI
 
Methods inherited from class javax.swing.AbstractButton
actionPropertyChanged, addActionListener, addChangeListener, addImpl, addItemListener, check, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, init, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, isSelected, paintBorder, paramString, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, setHideActionText, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setModel, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelected, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, update, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

popupListener

protected JMenu.WinListener popupListener
The window-closing listener for the popup.
Constructor Detail

JMenu

public JMenu()
Constructs a new JMenu with no text.


JMenu

public JMenu(Action a)
Constructs a menu whose properties are taken from the Action supplied.

Parameters:
a - an Action

JMenu

public JMenu(String s)
Constructs a new JMenu with the supplied string as its text.

Parameters:
s - the text for the menu label

JMenu

public JMenu(String s,
             boolean b)
Constructs a new JMenu with the supplied string as its text and specified as a tear-off menu or not.

Parameters:
s - the text for the menu label
b - can the menu be torn off (not yet implemented)
Method Detail

add

public JMenuItem add(Action a)
Creates a new menu item attached to the specified Action object and appends it to the end of this menu.

Parameters:
a - the Action for the menu item to be added

add

public Component add(Component c)
Appends a component to the end of this menu. Returns the component added.

Overrides:
add in class Container
Parameters:
c - the Component to add
Returns:
the Component added

add

public Component add(Component c,
                     int index)
Adds the specified component to this container at the given position. If index equals -1, the component will be appended to the end.

Overrides:
add in class Container
Parameters:
c - the Component to add
index - the position at which to insert the component
Returns:
the Component added

add

public JMenuItem add(JMenuItem menuItem)
Appends a menu item to the end of this menu. Returns the menu item added.

Parameters:
menuItem - the JMenuitem to be added
Returns:
the JMenuItem added

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

addMenuListener

public void addMenuListener(MenuListener l)
Adds a listener for menu events.

Parameters:
l - the listener to be added

addSeparator

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


applyComponentOrientation

public void applyComponentOrientation(ComponentOrientation o)
Sets the ComponentOrientation property of this menu and all components contained within it. This includes all components returned by {@link #getMenuComponents getMenuComponents}.

Overrides:
applyComponentOrientation in class Container
Parameters:
o - the new component orientation of this menu and the components contained within it.

createActionChangeListener

protected PropertyChangeListener createActionChangeListener(JMenuItem b)
Returns a properly configured PropertyChangeListener which updates the control as changes to the Action occur.

Parameters:
b

createActionComponent

protected JMenuItem createActionComponent(Action a)
Factory method which creates the JMenuItem for Actions added to the JMenu.

Parameters:
a - the Action for the menu item to be added
Returns:
the new menu item

createWinListener

protected JMenu.WinListener createWinListener(JPopupMenu p)
Creates a window-closing listener for the popup.

Parameters:
p - the JPopupMenu
Returns:
the new window-closing listener

doClick

public void doClick(int pressTime)
Programmatically performs a "click". This overrides the method AbstractButton.doClick in order to make the menu pop up.

Overrides:
doClick in class AbstractButton
Parameters:
pressTime - indicates the number of milliseconds the button was pressed for

fireMenuCanceled

protected void fireMenuCanceled()
Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.


fireMenuDeselected

protected void fireMenuDeselected()
Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.


fireMenuSelected

protected void fireMenuSelected()
Notifies all listeners that have registered interest for notification on this event type. The event instance is created lazily.


getAccessibleContext

public AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this JMenu. For JMenus, the AccessibleContext takes the form of an AccessibleJMenu. A new AccessibleJMenu instance is created if necessary.

Overrides:
getAccessibleContext in class JMenuItem
Returns:
an AccessibleJMenu that serves as the AccessibleContext of this JMenu

getComponent

public Component getComponent()
Returns the java.awt.Component used to paint this MenuElement. The returned component is used to convert events and detect if an event is inside a menu component.

Overrides:
getComponent in class JMenuItem

getDelay

public int getDelay()
Returns the suggested delay, in milliseconds, before submenus are popped up or down. Each look and feel (L&F) may determine its own policy for observing the delay property. In most cases, the delay is not observed for top level menus or while dragging. The default for delay is 0. This method is a property of the look and feel code and is used to manage the idiosyncracies of the various UI implementations.

Returns:
the delay property

getItem

public JMenuItem getItem(int pos)
Returns the JMenuItem at the specified position. If the component at pos is not a menu item, null is returned. This method is included for AWT compatibility.

Parameters:
pos - an integer specifying the position
Returns:
the menu item at the specified position; or null if the item as the specified position is not a menu item

getItemCount

public int getItemCount()
Returns the number of items on the menu, including separators. This method is included for AWT compatibility.

Returns:
an integer equal to the number of items on the menu

getMenuComponent

public Component getMenuComponent(int n)
Returns the component at position n.

Parameters:
n - the position of the component to be returned
Returns:
the component requested, or null if there is no popup menu

getMenuComponentCount

public int getMenuComponentCount()
Returns the number of components on the menu.

Returns:
an integer containing the number of components on the menu

getMenuComponents

public Component[] getMenuComponents()
Returns an array of Components of the menu's subcomponents. Note that this returns all Components in the popup menu, including separators.

Returns:
an array of Components or an empty array if there is no popup menu

getMenuListeners

public MenuListener[] getMenuListeners()
Returns an array of all the MenuListeners added to this JMenu with addMenuListener().

Returns:
all of the MenuListeners added or an empty array if no listeners have been added

getPopupMenu

public JPopupMenu getPopupMenu()
Returns the popupmenu associated with this menu. If there is no popupmenu, it will create one.


getPopupMenuOrigin

protected Point getPopupMenuOrigin()
Computes the origin for the JMenu's popup menu. This method uses Look and Feel properties named Menu.menuPopupOffsetX, Menu.menuPopupOffsetY, Menu.submenuPopupOffsetX, and Menu.submenuPopupOffsetY to adjust the exact location of popup.

Returns:
a Point in the coordinate space of the menu which should be used as the origin of the JMenu's popup menu

getSubElements

public MenuElement[] getSubElements()
Returns an array of MenuElements containing the submenu for this menu component. If popup menu is null returns an empty array. This method is required to conform to the MenuElement interface. Note that since JSeparators do not conform to the MenuElement interface, this array will only contain JMenuItems.

Overrides:
getSubElements in class JMenuItem
Returns:
an array of MenuElement objects

getUIClassID

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

Overrides:
getUIClassID in class JMenuItem
Returns:
the string "MenuUI"

insert

public JMenuItem insert(Action a,
                        int pos)
Inserts a new menu item attached to the specified Action object at a given position.

Parameters:
a - the Action object for the menu item to add
pos - an integer specifying the position at which to add the new menu item

insert

public JMenuItem insert(JMenuItem mi,
                        int pos)
Inserts the specified JMenuitem at a given position.

Parameters:
mi - the JMenuitem to add
pos - an integer specifying the position at which to add the new JMenuitem
Returns:
the new menu item

insert

public void insert(String s,
                   int pos)
Inserts a new menu item with the specified text at a given position.

Parameters:
s - the text for the menu item to add
pos - an integer specifying the position at which to add the new menu item

insertSeparator

public void insertSeparator(int index)
Inserts a separator at the specified position.

Parameters:
index - an integer specifying the position at which to insert the menu separator

isMenuComponent

public boolean isMenuComponent(Component c)
Returns true if the specified component exists in the submenu hierarchy.

Parameters:
c - the Component to be tested
Returns:
true if the Component exists, false otherwise

isPopupMenuVisible

public boolean isPopupMenuVisible()
Returns true if the menu's popup window is visible.

Returns:
true if the menu is visible, else false

isSelected

public boolean isSelected()
Returns true if the menu is currently selected (highlighted).

Overrides:
isSelected in class AbstractButton
Returns:
true if the menu is selected, else false

isTearOff

public boolean isTearOff()
Returns true if the menu can be torn off. This method is not yet implemented.

Returns:
true if the menu can be torn off, else false

isTopLevelMenu

public boolean isTopLevelMenu()
Returns true if the menu is a 'top-level menu', that is, if it is the direct child of a menubar.

Returns:
true if the menu is activated from the menu bar; false if the menu is activated from a menu item on another menu

menuSelectionChanged

public void menuSelectionChanged(boolean isIncluded)
Messaged when the menubar selection changes to activate or deactivate this menu. Overrides JMenuItem.menuSelectionChanged.

Overrides:
menuSelectionChanged in class JMenuItem
Parameters:
isIncluded - true if this menu is active, false if it is not

paramString

protected String paramString()
Returns a string representation of this JMenu. 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 JMenuItem
Returns:
a string representation of this JMenu.

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

remove

public void remove(Component c)
Removes the component c from this menu.

Overrides:
remove in class Container
Parameters:
c - the component to be removed

remove

public void remove(int pos)
Removes the menu item at the specified index from this menu.

Overrides:
remove in class Container
Parameters:
pos - the position of the item to be removed

remove

public void remove(JMenuItem item)
Removes the specified menu item from this menu. If there is no popup menu, this method will have no effect.

Parameters:
item - the JMenuItem to be removed from the menu

removeAll

public void removeAll()
Removes all menu items from this menu.

Overrides:
removeAll in class Container

removeMenuListener

public void removeMenuListener(MenuListener l)
Removes a listener for menu events.

Parameters:
l - the listener to be removed

setAccelerator

public void setAccelerator(KeyStroke keyStroke)
setAccelerator is not defined for JMenu. Use setMnemonic instead.

Overrides:
setAccelerator in class JMenuItem
Parameters:
keyStroke - the keystroke combination which will invoke the JMenuItem's actionlisteners without navigating the menu hierarchy

setComponentOrientation

public void setComponentOrientation(ComponentOrientation o)
Overrides:
setComponentOrientation in class Component
Parameters:
o

setDelay

public void setDelay(int d)
Sets the suggested delay before the menu's PopupMenu is popped up or down. Each look and feel (L&F) may determine it's own policy for observing the delay property. In most cases, the delay is not observed for top level menus or while dragging. This method is a property of the look and feel code and is used to manage the idiosyncracies of the various UI implementations.

Parameters:
d - the number of milliseconds to delay

setMenuLocation

public void setMenuLocation(int x,
                            int y)
Sets the location of the popup component.

Parameters:
x - the x coordinate of the popup's new position
y - the y coordinate of the popup's new position

setModel

public void setModel(ButtonModel newModel)
Sets the data model for the "menu button" -- the label that the user clicks to open or close the menu.

Overrides:
setModel in class JMenuItem
Parameters:
newModel - the ButtonModel

setPopupMenuVisible

public void setPopupMenuVisible(boolean b)
Sets the visibility of the menu's popup. If the menu is not enabled, this method will have no effect.

Parameters:
b - a boolean value -- true to make the menu visible, false to hide it

setSelected

public void setSelected(boolean b)
Sets the selection status of the menu.

Overrides:
setSelected in class AbstractButton
Parameters:
b - true to select (highlight) the menu; false to de-select the menu

updateUI

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

Overrides:
updateUI in class JMenuItem


This documentation differs from the official API. Jadeite adds extra features to the API including: variable font sizes, constructions examples, placeholders for classes and methods, and auto-generated “See Also” links. Additionally it is missing some items found in standard Javadoc documentation, including: generics type information, “Deprecated” tags and comments, “See Also” links, along with other minor differences. Please send any questions or feedback to bam@cs.cmu.edu.
This page displays the Jadeite version of the documention, which is derived from the offical documentation that contains this copyright notice:
Copyright 2008 Sun Microsystems, Inc. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.
The official Sun™ documentation can be found here at http://java.sun.com/javase/6/docs/api/.