javax.swing

Class JMenu

Implemented Interfaces:
Accessible, ImageObserver, ItemSelectable, MenuContainer, MenuElement, Serializable, SwingConstants

public class JMenu
extends JMenuItem
implements Accessible, MenuElement

This class represents a menu that can be added to a menu bar or can be a submenu in some other menu. When JMenu is selected it displays JPopupMenu containing its menu items.

JMenu's fires MenuEvents when this menu's selection changes. If this menu is selected, then fireMenuSelectedEvent() is invoked. In case when menu is deselected or cancelled, then fireMenuDeselectedEvent() or fireMenuCancelledEvent() is invoked, respectivelly.

See Also:
Serialized Form

Nested Class Summary

protected class
JMenu.AccessibleJMenu
Implements support for assisitive technologies for JMenu.
protected class
JMenu.WinListener

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.BltBufferStrategy, Component.FlipBufferStrategy

Field Summary

protected JMenu.WinListener
popupListener

Fields inherited from class javax.swing.AbstractButton

BORDER_PAINTED_CHANGED_PROPERTY, 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, MARGIN_CHANGED_PROPERTY, MNEMONIC_CHANGED_PROPERTY, 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, actionListener, changeEvent, changeListener, itemListener, model

Fields inherited from class javax.swing.JComponent

TOOL_TIP_TEXT_KEY, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW, accessibleContext, listenerList, ui

Fields inherited from class java.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT

Fields inherited from interface java.awt.image.ImageObserver

ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH

Fields inherited from interface javax.swing.SwingConstants

BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST

Constructor Summary

JMenu()
Creates a new JMenu object.
JMenu(String text)
Creates a new JMenu with the specified label.
JMenu(String text, boolean tearoff)
Creates a new JMenu with specified label and an option for this menu to be tear-off menu.
JMenu(Action action)
Creates a new JMenu object.

Method Summary

Component
add(Component component)
Adds specified component to this menu.
Component
add(Component component, int index)
Adds specified component to this menu at the given index
JMenuItem
add(String text)
Adds JMenuItem constructed with the specified label to this menu
JMenuItem
add(Action action)
Adds JMenuItem constructed using properties from specified action.
JMenuItem
add(JMenuItem item)
Adds specified menu item to this menu
void
addMenuListener(MenuListener listener)
Adds MenuListener to the menu
void
addSeparator()
Adds separator to the end of the menu items in the menu.
protected PropertyChangeListener
createActionChangeListener(JMenuItem item)
Creates ActionChangeListener to listen for PropertyChangeEvents occuring in the action that is associated with this menu
protected JMenuItem
createActionComponent(Action action)
Creates and returns JMenuItem associated with the given action
protected JMenu.WinListener
createWinListener(JPopupMenu popup)
Creates WinListener that listens to the menu;s popup menu.
void
doClick(int time)
Programatically performs click
protected void
fireMenuCanceled()
This method fires MenuEvents to all menu's MenuListeners.
protected void
fireMenuDeselected()
This method fires MenuEvents to all menu's MenuListeners.
protected void
fireMenuSelected()
This method fires MenuEvents to all menu's MenuListeners.
AccessibleContext
getAccessibleContext()
If a component supports the Accessibility API then this method should not return null.
Component
getComponent()
int
getDelay()
Returns delay property.
JMenuItem
getItem(int index)
Returns menu item located at the specified index in the menu
int
getItemCount()
Returns number of items in the menu including separators.
Component
getMenuComponent(int index)
Returns menu component located at the givent index in the menu
int
getMenuComponentCount()
Returns number of menu components in this menu
Component[]
getMenuComponents()
Return components belonging to this menu
MenuListener[]
getMenuListeners()
Returns all registered MenuListener objects.
JPopupMenu
getPopupMenu()
Returns popup menu associated with the menu.
protected Point
getPopupMenuOrigin()
Returns origin point of the popup menu.
MenuElement[]
getSubElements()
Method of MenuElement interface.
String
getUIClassID()
This method returns a name to identify which look and feel class will be the UI delegate for the menu.
void
insert(String text, int index)
Creates JMenuItem with the specified text and inserts it in the at the specified index
JMenuItem
insert(Action action, int index)
Creates JMenuItem with the associated action and inserts it to the menu at the specified index.
JMenuItem
insert(JMenuItem item, int index)
Creates JMenuItem with the specified text and inserts it in the at the specified index.
void
insertSeparator(int index)
Inserts separator in the menu at the specified index.
boolean
isMenuComponent(Component component)
Checks if given component exists in this menu.
boolean
isPopupMenuVisible()
Checks if PopupMenu associated with this menu is visible
boolean
isSelected()
Returns true if the menu is selected and false otherwise
boolean
isTearOff()
Checks if this menu is a tear-off menu.
boolean
isTopLevelMenu()
Checks if this menu is a top level menu.
void
menuSelectionChanged(boolean changed)
Method of the MenuElementInterface.
protected String
paramString()
A string that describes this JMenu.
protected void
processKeyEvent(KeyEvent event)
This method process KeyEvent occuring when the menu is visible
void
remove(int index)
Removes component at the specified index from this menu
void
remove(Component component)
Removes given component from this menu.
void
remove(JMenuItem item)
Removes given menu item from this menu.
void
removeAll()
Removes all menu items from the menu
void
removeMenuListener(MenuListener listener)
Removes MenuListener from the menu
void
setAccelerator(KeyStroke keystroke)
This method is overriden with empty implementation, s.t the accelerator couldn't be set for the menu.
void
setDelay(int delay)
Sets delay property for this menu.
void
setMenuLocation(int x, int y)
Sets location at which popup menu should be displayed The location given is relative to this menu item
void
setModel(ButtonModel model)
Sets model for this menu.
void
setPopupMenuVisible(boolean popup)
Sets popup menu visibility
void
setSelected(boolean selected)
Changes this menu selected state if selected is true and false otherwise This method fires menuEvents to menu's registered listeners.
void
updateUI()
This method sets this menuItem's UI to the UIManager's default for the current look and feel.

Methods inherited from class javax.swing.JMenuItem

addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, createActionPropertyChangeListener, 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, setUI, updateUI

Methods inherited from class javax.swing.AbstractButton

addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, createActionListener, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, 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, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setEnabled, setFocusPainted, 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, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, 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, 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, extends EventListener> T[] getListeners, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponentZOrder, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, 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, 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, extends EventListener> T[] getListeners, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, 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, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, 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, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusable, 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, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusable, 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, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

popupListener

protected JMenu.WinListener popupListener

Constructor Details

JMenu

public JMenu()
Creates a new JMenu object.

JMenu

public JMenu(String text)
Creates a new JMenu with the specified label.
Parameters:
text - label for this menu

JMenu

public JMenu(String text,
             boolean tearoff)
Creates a new JMenu with specified label and an option for this menu to be tear-off menu.
Parameters:
text - label for this menu
tearoff - true if this menu should be tear-off and false otherwise

JMenu

public JMenu(Action action)
Creates a new JMenu object.
Parameters:
action - Action that is used to create menu item tha will be added to the menu.

Method Details

add

public Component add(Component component)
Adds specified component to this menu.
Overrides:
add in interface Container
Parameters:
component - Component to add to this menu
Returns:
Component that was added

add

public Component add(Component component,
                     int index)
Adds specified component to this menu at the given index
Overrides:
add in interface Container
Parameters:
component - Component to add
index - Position of this menu item in the menu
Returns:
Component that was added