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:
ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, MenuElement, 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
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
 
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
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JMenu()
          Creates a new JMenu object.
JMenu(Action action)
          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.
 
Method Summary
 JMenuItem add(Action action)
          Adds JMenuItem constructed using properties from specified action.
 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(JMenuItem item)
          Adds specified menu item to this menu
 JMenuItem add(String text)
          Adds JMenuItem constructed with the specified label 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()
          Returns the object that provides accessibility features for this JMenuItem component.
 Component getComponent()
          Returns reference to the component that will paint this menu item.
 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.
 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 insert(String text, 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(Component component)
          Removes given component from this menu.
 void remove(int index)
          Removes component at the specified index 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, getMenuDragMouseListeners, getMenuKeyListeners, init, isArmed, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setArmed, setEnabled, setUI
 
Methods inherited from class javax.swing.AbstractButton
addActionListener, addChangeListener, addImpl, addItemListener, checkHorizontalKey, checkVerticalKey, createActionListener, createChangeListener, createItemListener, 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, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, paintBorder, removeActionListener, removeChangeListener, removeItemListener, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHorizontalAlignment, setHorizontalTextPosition, setIcon, setIconTextGap, setLabel, setLayout, setMargin, setMnemonic, setMnemonic, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
Methods inherited from class javax.swing.JComponent
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, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, 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, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, addContainerListener, 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, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, 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, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, 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, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface javax.swing.MenuElement
processKeyEvent, processMouseEvent
 

Field Detail

popupListener

protected JMenu.WinListener popupListener
Constructor Detail

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(Action action)
Creates a new JMenu object.

Parameters:
action - Action that is used to create menu item tha will be added to the 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
Method Detail

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

add

public Component add(Component component)
Adds specified component to this menu.

Overrides:
add in class 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 class 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

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

remove

public void remove(int index)
Removes component at the specified index from this menu

Overrides:
remove in class 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 class Container
Parameters:
component - Component to remove

removeAll

public void removeAll()
Removes all menu items from the menu

Overrides:
removeAll in class Container

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(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

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

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 class JMenuItem

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 class JMenuItem
Returns:
The Look and Feel classID. "MenuUI"
See Also:
JComponent.setUI(javax.swing.plaf.ComponentUI), JComponent.updateUI()

setModel

public void setModel(ButtonModel model)
Sets model for this menu.

Overrides:
setModel in class AbstractButton
Parameters:
model - model to set

isSelected

public boolean isSelected()
Returns true if the menu is selected and false otherwise

Overrides:
isSelected in class AbstractButton
Returns:
true if the menu is selected 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 class AbstractButton
Parameters:
selected - true if the menu should be selected 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.

setPopupMenuVisible

public void setPopupMenuVisible(boolean popup)
Sets popup menu visibility

Parameters:
popup - true if popup should be visible and false otherwise

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

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

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

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

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

addSeparator

public void addSeparator()
Adds separator to the end of the menu items in 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

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
See Also:
getMenuComponentCount()

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

getMenuComponentCount

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

Returns:
number of menu components in this 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

getMenuComponents

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

Returns:
components belonging to this menu

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

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

getPopupMenu

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

Returns:
popup menu associated with the menu.

addMenuListener

public void addMenuListener(MenuListener listener)
Adds MenuListener to the menu

Parameters:
listener - MenuListener to add

removeMenuListener

public void removeMenuListener(MenuListener listener)
Removes MenuListener from the menu

Parameters:
listener - MenuListener to remove

getMenuListeners

public MenuListener[] getMenuListeners()
Returns all registered MenuListener objects.

Returns:
an array of listeners
Since:
1.4

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.


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.


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.


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

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 class JMenuItem
Parameters:
changed - true if the menu was selected and false otherwise

getSubElements

public MenuElement[] getSubElements()
Method of MenuElement interface. Returns sub components of this menu.

Specified by:
getSubElements in interface MenuElement
Overrides:
getSubElements in class JMenuItem
Returns:
array containing popupMenu that is associated with this menu

getComponent

public Component getComponent()
Description copied from class: JMenuItem
Returns reference to the component that will paint this menu item.

Specified by:
getComponent in interface MenuElement
Overrides:
getComponent in class JMenuItem
Returns:
Returns reference to itself

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 class JMenuItem
Parameters:
keystroke - accelerator for this menu

processKeyEvent

protected void processKeyEvent(KeyEvent event)
This method process KeyEvent occuring when the menu is visible

Overrides:
processKeyEvent in class JComponent
Parameters:
event - The KeyEvent
See Also:
KeyListener, Component.addKeyListener(KeyListener), Component.enableEvents(long)

doClick

public void doClick(int time)
Programatically performs click

Overrides:
doClick in class AbstractButton
Parameters:
time - Number of milliseconds for which this menu stays pressed

paramString

protected String paramString()
A string that describes this JMenu. Normally only used for debugging.

Overrides:
paramString in class JMenuItem
Returns:
A string describing this JMenu

getAccessibleContext

public AccessibleContext getAccessibleContext()
Description copied from class: JMenuItem
Returns the object that provides accessibility features for this JMenuItem component.

Specified by:
getAccessibleContext in interface Accessible
Overrides:
getAccessibleContext in class JMenuItem
Returns:
The accessible context (an instance of JMenuItem.AccessibleJMenuItem).