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

add

public JMenuItem add(String text)
Adds JMenuItem constructed with the specified label to this menu
Parameters:
text - label for the menu item that will be added
Returns:
Menu Item that was added to this menu

add

public JMenuItem add(Action action)
Adds JMenuItem constructed using properties from specified action.
Parameters:
action - action to construct the menu item with
Returns:
Menu Item that was added to this menu

add

public JMenuItem add(JMenuItem item)
Adds specified menu item to this menu
Parameters:
item - Menu item to add to this menu
Returns:
Menu item that was added

addMenuListener

public void addMenuListener(MenuListener listener)
Adds MenuListener to the menu
Parameters:
listener - MenuListener to add

addSeparator

public void addSeparator()
Adds separator to the end of the menu items in the menu.

createActionChangeListener

protected PropertyChangeListener createActionChangeListener(JMenuItem item)
Creates ActionChangeListener to listen for PropertyChangeEvents occuring in the action that is associated with this menu
Parameters:
item - menu that contains action to listen to
Returns:
The PropertyChangeListener

createActionComponent

protected JMenuItem createActionComponent(Action action)
Creates and returns JMenuItem associated with the given action
Parameters:
action - Action to use for creation of JMenuItem
Returns:
JMenuItem that was creted with given action

createWinListener

protected JMenu.WinListener createWinListener(JPopupMenu popup)
Creates WinListener that listens to the menu;s popup menu.
Parameters:
popup - JPopupMenu to listen to
Returns:
The WinListener

doClick

public void doClick(int time)
Programatically performs click
Overrides:
doClick in interface AbstractButton
Parameters:
time - Number of milliseconds for which this menu stays pressed

fireMenuCanceled

protected void fireMenuCanceled()
This method fires MenuEvents to all menu's MenuListeners. In this case menuSelected() method of MenuListeners is called to indicated that the menu was cancelled. The menu is cancelled when it's popup menu is close without selection.

fireMenuDeselected

protected void fireMenuDeselected()
This method fires MenuEvents to all menu's MenuListeners. In this case menuDeselected() method of MenuListeners is called to indicated that the menu was deselected.

fireMenuSelected

protected void fireMenuSelected()
This method fires MenuEvents to all menu's MenuListeners. In this case menuSelected() method of MenuListeners is called to indicated that the menu was selected.

getAccessibleContext

public AccessibleContext getAccessibleContext()
If a component supports the Accessibility API then this method should not return null. Only classes which must extend an accessible class, but must not itself be accessible, may return null.
Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in interface JMenuItem
Returns:
the context associated with this accessible object

getComponent

public Component getComponent()
Specified by:
getComponent in interface MenuElement
Overrides:
getComponent in interface JMenuItem
Returns:
Returns reference to itself

getDelay

public int getDelay()
Returns delay property.
Returns:
delay property, indicating number of milliseconds before popup menu associated with the menu appears or disappears after menu was selected or deselected respectively

getItem

public JMenuItem getItem(int index)
Returns menu item located at the specified index in the menu
Parameters:
index - Index at which to look for the menu item
Returns:
menu item located at the specified index in the menu

getItemCount

public int getItemCount()
Returns number of items in the menu including separators.
Returns:
number of items in the menu

getMenuComponent

public Component getMenuComponent(int index)
Returns menu component located at the givent index in the menu
Parameters:
index - index at which to get the menu component in the menu
Returns:
Menu Component located in the menu at the specified index

getMenuComponentCount

public int getMenuComponentCount()
Returns number of menu components in this menu
Returns:
number of menu components in this menu

getMenuComponents

public Component[] getMenuComponents()
Return components belonging to this menu
Returns:
components belonging to this menu

getMenuListeners

public MenuListener[] getMenuListeners()
Returns all registered MenuListener objects.
Returns:
an array of listeners
Since:
1.4

getPopupMenu

public JPopupMenu getPopupMenu()
Returns popup menu associated with the menu.
Returns:
popup menu associated with the menu.

getPopupMenuOrigin

protected Point getPopupMenuOrigin()
Returns origin point of the popup menu. This takes the screen bounds into account and places the popup where it fits best.
Returns:
the origin of the popup menu

getSubElements

public MenuElement[] getSubElements()
Method of MenuElement interface. Returns sub components of this menu.
Specified by:
getSubElements in interface MenuElement
Overrides:
getSubElements in interface JMenuItem
Returns:
array containing popupMenu that is associated with this menu

getUIClassID

public String getUIClassID()
This method returns a name to identify which look and feel class will be the UI delegate for the menu.
Overrides:
getUIClassID in interface JMenuItem
Returns:
The Look and Feel classID. "MenuUI"

insert

public void insert(String text,
                   int index)
Creates JMenuItem with the specified text and inserts it in the at the specified index
Parameters:
text - label for the new menu item
index - index at which to insert newly created menu item.

insert

public JMenuItem insert(Action action,
                        int index)
Creates JMenuItem with the associated action and inserts it to the menu at the specified index. IllegalArgumentException is thrown if index is less than 0
Parameters:
action - Action for the new menu item
index - index at which to insert newly created menu item.
Returns:
Menu item that was added to the menu

insert

public JMenuItem insert(JMenuItem item,
                        int index)
Creates JMenuItem with the specified text and inserts it in the at the specified index. IllegalArgumentException is thrown if index is less than 0
Parameters:
item - menu item to insert
index - index at which to insert menu item.
Returns:
Menu item that was added to the menu

insertSeparator

public void insertSeparator(int index)
Inserts separator in the menu at the specified index.
Parameters:
index - Index at which separator should be inserted

isMenuComponent

public boolean isMenuComponent(Component component)
Checks if given component exists in this menu. The submenus of this menu are checked as well
Parameters:
component - Component to look for
Returns:
true if the given component exists in this menu, and false otherwise

isPopupMenuVisible

public boolean isPopupMenuVisible()
Checks if PopupMenu associated with this menu is visible
Returns:
true if the popup associated with this menu is currently visible on the screen and false otherwise.

isSelected

public boolean isSelected()
Returns true if the menu is selected and false otherwise
Overrides:
isSelected in interface AbstractButton
Returns:
true if the menu is selected and false otherwise

isTearOff

public boolean isTearOff()
Checks if this menu is a tear-off menu.
Returns:
true if this menu is a tear-off menu and false otherwise

isTopLevelMenu

public boolean isTopLevelMenu()
Checks if this menu is a top level menu. The menu is top level menu if it is inside the menu bar. While if the menu inside some other menu, it is considered to be a pull-right menu.
Returns:
true if this menu is top level menu, and false otherwise

menuSelectionChanged

public void menuSelectionChanged(boolean changed)
Method of the MenuElementInterface. It reacts to the selection changes in the menu. If this menu was selected, then it displayes popup menu associated with it and if this menu was deselected it hides the popup menu.
Specified by:
menuSelectionChanged in interface MenuElement
Overrides:
menuSelectionChanged in interface JMenuItem
Parameters:
changed - true if the menu was selected and false otherwise

paramString

protected String paramString()
A string that describes this JMenu. Normally only used for debugging.
Overrides:
paramString in interface JMenuItem
Returns:
A string describing this JMenu

processKeyEvent

protected void processKeyEvent(KeyEvent event)
This method process KeyEvent occuring when the menu is visible
Overrides:
processKeyEvent in interface JComponent
Parameters:
event - The KeyEvent

remove

public void remove(int index)
Removes component at the specified index from this menu
Overrides:
remove in interface Container
Parameters:
index - Position of the component that needs to be removed in the menu

remove

public void remove(Component component)
Removes given component from this menu.
Overrides:
remove in interface Container
Parameters:
component - Component to remove

remove

public void remove(JMenuItem item)
Removes given menu item from this menu. Nothing happens if this menu doesn't contain specified menu item.
Parameters:
item - Menu Item which needs to be removed

removeAll

public void removeAll()
Removes all menu items from the menu
Overrides:
removeAll in interface Container

removeMenuListener

public void removeMenuListener(MenuListener listener)
Removes MenuListener from the menu
Parameters:
listener - MenuListener to remove

setAccelerator

public void setAccelerator(KeyStroke keystroke)
This method is overriden with empty implementation, s.t the accelerator couldn't be set for the menu. The mnemonic should be used for the menu instead.
Overrides:
setAccelerator in interface JMenuItem
Parameters:
keystroke - accelerator for this menu

setDelay

public void setDelay(int delay)
Sets delay property for this menu. If given time for the delay property is negative, then IllegalArgumentException is thrown
Parameters:
delay - number of milliseconds before popup menu associated with the menu appears or disappears after menu was selected or deselected respectively

setMenuLocation

public void setMenuLocation(int x,
                            int y)
Sets location at which popup menu should be displayed The location given is relative to this menu item
Parameters:
x - x-coordinate of the menu location
y - y-coordinate of the menu location

setModel

public void setModel(ButtonModel model)
Sets model for this menu.
Overrides:
setModel in interface AbstractButton
Parameters:
model - model to set

setPopupMenuVisible

public void setPopupMenuVisible(boolean popup)
Sets popup menu visibility
Parameters:
popup - true if popup should be visible and false otherwise

setSelected

public 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.
Overrides:
setSelected in interface AbstractButton
Parameters:
selected - true if the menu should be selected and false otherwise

updateUI

public void updateUI()
This method sets this menuItem's UI to the UIManager's default for the current look and feel.
Overrides:
updateUI in interface JMenuItem

JMenu.java -- Copyright (C) 2002, 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.