javax.swing
Class JMenu

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.AbstractButton
                          |
                          +--javax.swing.JMenuItem
                                |
                                +--javax.swing.JMenu
All Implemented Interfaces:
Accessible, java.awt.image.ImageObserver, ItemSelectable, MenuContainer, MenuElement, Serializable, SwingConstants

public class JMenu
extends JMenuItem
implements Accessible, MenuElement

Safe:

See Also:
Serialized Form

Field Summary
private  Point customMenuLocation
           
private static boolean DEBUG
           
private  int delay
           
private static Hashtable listenerRegistry
           
private  ChangeListener menuChangeListener
           
private  MenuEvent menuEvent
           
protected  javax.swing.JMenu.WinListener popupListener
          The window-closing listener for the popup.
private  JPopupMenu popupMenu
           
private static boolean TRACE
           
private static String uiClassID
           
private static boolean VERBOSE
           
 
Fields inherited from class javax.swing.JMenuItem
 
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
_bounds, accessibleContext, listenerList, paintingChild, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
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
 
Constructor Summary
JMenu()
          Enabled: Constructs a new JMenu with no text.
JMenu(Action a)
          Enabled: Constructs a menu whose properties are taken from the Action supplied.
JMenu(String s)
          Enabled: Constructs a new JMenu with the supplied string as its text.
JMenu(String s, boolean b)
          Enabled: Constructs a new JMenu with the supplied string as its text and specified as a tear-off menu or not.
 
Method Summary
 JMenuItem add(Action a)
          Enabled: Creates a new menu item attached to the specified Action object and appends it to the end of this menu.
 Component add(Component c)
          Enabled: Appends a component to the end of this menu.
 Component add(Component c, int index)
          Enabled: Adds the specified component to this container at the given position.
 JMenuItem add(JMenuItem menuItem)
          Enabled: Appends a menu item to the end of this menu.
 JMenuItem add(String s)
          Enabled: Creates a new menu item with the specified text and appends it to the end of this menu.
 void addMenuListener(MenuListener l)
          Suppressed: Adds a listener for menu events.
 void addSeparator()
          Enabled: Appends a new separator to the end of the menu.
 void applyComponentOrientation(ComponentOrientation o)
          Suppressed: Sets the ComponentOrientation property of this menu and all components contained within it.
private  MenuElement[] buildMenuElementArray(JMenu leaf)
           
protected  void configurePropertiesFromAction(Action a)
          Factory method which sets the ActionEvent source's properties according to values from the Action instance.
protected  java.beans.PropertyChangeListener createActionChangeListener(JMenuItem b)
          Returns a properly configured PropertyChangeListener which updates the control as changes to the Action occur.
protected  JMenuItem createActionComponent(Action a)
          Factory method which creates the JMenuItem for Actions added to the JMenu.
private  ChangeListener createMenuChangeListener()
           
protected  javax.swing.JMenu.WinListener createWinListener(JPopupMenu p)
          Creates a window-closing listener for the popup.
 void doClick(int pressTime)
          Suppressed: Programmatically performs a "click".
private  void ensurePopupMenuCreated()
           
protected  void fireMenuCanceled()
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireMenuDeselected()
          Notifies all listeners that have registered interest for notification on this event type.
protected  void fireMenuSelected()
          Notifies all listeners that have registered interest for notification on this event type.
 AccessibleContext getAccessibleContext()
          Suppressed: Gets the AccessibleContext associated with this JMenu.
 Component getComponent()
          Enabled: Returns the java.awt.Component used to paint this MenuElement.
private  Point getCustomMenuLocation()
           
 int getDelay()
          Enabled: Returns the suggested delay, in milliseconds, before submenus are popped up or down.
 JMenuItem getItem(int pos)
          Suppressed: Returns the JMenuItem at the specified position.
 int getItemCount()
          Enabled: Returns the number of items on the menu, including separators.
 Component getMenuComponent(int n)
          Enabled: Returns the component at position n.
 int getMenuComponentCount()
          Enabled: Returns the number of components on the menu.
 Component[] getMenuComponents()
          Enabled: Returns an array of Components of the menu's subcomponents.
 MenuListener[] getMenuListeners()
          Suppressed: Returns an array of all the MenuListeners added to this JMenu with addMenuListener().
 JPopupMenu getPopupMenu()
          Enabled: Returns the popupmenu associated with this menu.
protected  Point getPopupMenuOrigin()
          Computes the origin for the JMenu's popup menu.
 MenuElement[] getSubElements()
          Enabled: Returns an array of MenuElements containing the submenu for this menu component.
 String getUIClassID()
          Enabled: Returns the name of the L&F class that renders this component.
(package private)  void initFocusability()
          Overriden to do nothing.
 JMenuItem insert(Action a, int pos)
          Enabled: Inserts a new menu item attached to the specified Action object at a given position.
 JMenuItem insert(JMenuItem mi, int pos)
          Enabled: Inserts the specified JMenuitem at a given position.
 void insert(String s, int pos)
          Enabled: Inserts a new menu item with the specified text at a given position.
 void insertSeparator(int index)
          Enabled: Inserts a separator at the specified position.
 boolean isMenuComponent(Component c)
          Enabled: Returns true if the specified component exists in the submenu hierarchy.
 boolean isPopupMenuVisible()
          Enabled: Returns true if the menu's popup window is visible.
 boolean isSelected()
          Enabled: Returns true if the menu is currently selected (highlighted).
 boolean isTearOff()
          Enabled: Returns true if the menu can be torn off.
 boolean isTopLevelMenu()
          Enabled: 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)
          Enabled: Messaged when the menubar selection changes to activate or deactivate this menu.
protected  String paramString()
          Returns a string representation of this JMenu.
protected  void processKeyEvent(KeyEvent evt)
          Processes key stroke events such as mnemonics and accelerators.
 void remove(Component c)
          Enabled: Removes the component c from this menu.
 void remove(int pos)
          Enabled: Removes the menu item at the specified index from this menu.
 void remove(JMenuItem item)
          Suppressed: Removes the specified menu item from this menu.
 void removeAll()
          Enabled: Removes all menu items from this menu.
 void removeMenuListener(MenuListener l)
          Enabled: Removes a listener for menu events.
 void setAccelerator(KeyStroke keyStroke)
          Enabled: setAccelerator is not defined for JMenu.
 void setComponentOrientation(ComponentOrientation o)
          Suppressed:
 void setDelay(int d)
          Enabled: Sets the suggested delay before the menu's PopupMenu is popped up or down.
 void setMenuLocation(int x, int y)
          Enabled: Sets the location of the popup component.
 void setModel(ButtonModel newModel)
          Enabled: Sets the data model for the "menu button" -- the label that the user clicks to open or close the menu.
 void setPopupMenuVisible(boolean b)
          Enabled: Sets the visibility of the menu's popup.
 void setSelected(boolean b)
          Enabled: Sets the selection status of the menu.
private  Point translateToPopupMenu(int x, int y)
           
private  Point translateToPopupMenu(Point p)
           
 void updateUI()
          Enabled: Resets the UI property with a value from the current look and feel.
private  void writeObject(ObjectOutputStream s)
          See readObject and writeObject in JComponent for more information about serialization in Swing.
 
Methods inherited from class javax.swing.JMenuItem
addMenuDragMouseListener, addMenuKeyListener, alwaysOnTop, 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, addItemListener, checkHorizontalKey, checkVerticalKey, configurePropertiesFromAction, 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, setMargin, setMnemonic, setMnemonic, setMultiClickThreshhold, setPressedIcon, setRolloverEnabled, setRolloverIcon, setRolloverSelectedIcon, setSelectedIcon, setText, setUI, setVerticalAlignment, setVerticalTextPosition
 
Methods inherited from class javax.swing.JComponent
_paintImmediately, addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, checkIfChildObscuredBySibling, componentInputMapChanged, computeVisibleRect, computeVisibleRect, compWriteObjectNotify, contains, createToolTip, disable, enable, enableSerialization, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getCreatedDoubleBuffer, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getManagingFocusBackwardTraversalKeys, getManagingFocusForwardTraversalKeys, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getWriteObjCounter, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyBindings, processKeyBindingsForAllComponents, processMouseMotionEvent, putClientProperty, rectangleIsObscured, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setCreatedDoubleBuffer, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPaintingChild, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, setWriteObjCounter, shouldDebugGraphics, superProcessMouseMotionEvent, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, addContainerListener, addImpl, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, get, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, iterate, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, size, transferFocusBackward, 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, 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, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, toString, transferFocus, transferFocus, 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

uiClassID

private static final String uiClassID
See Also:
getUIClassID(), JMenuItem.readObject(java.io.ObjectInputStream)

popupMenu

private JPopupMenu popupMenu

menuChangeListener

private ChangeListener menuChangeListener

menuEvent

private MenuEvent menuEvent

listenerRegistry

private static Hashtable listenerRegistry

delay

private int delay

customMenuLocation

private Point customMenuLocation

TRACE

private static final boolean TRACE

VERBOSE

private static final boolean VERBOSE

DEBUG

private static final boolean DEBUG

popupListener

protected javax.swing.JMenu.WinListener popupListener
The window-closing listener for the popup.

See Also:
WinListener
Constructor Detail

JMenu

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


JMenu

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

Parameters:
s - the text for the menu label

JMenu

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

Parameters:
a - an Action
Since:
1.3

JMenu

public JMenu(String s,
             boolean b)
Enabled: 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

initFocusability

void initFocusability()
Overriden to do nothing. We want JMenu to be focusable, but JMenuItem doesn't want to be, thus we override this do nothing. We don't invoke setFocusable(true) after super's constructor has completed as this has the side effect that JMenu will be considered traversable via the keyboard, which we don't want. Making a Component traversable by the keyboard after invoking setFocusable(true) is OK, as setFocusable is new API and is speced as such, but internally we don't want to use it like this else we change the keyboard traversability.

Overrides:
initFocusability in class JMenuItem

updateUI

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

Overrides:
updateUI in class JMenuItem
See Also:
JComponent.updateUI()

getUIClassID

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

Overrides:
getUIClassID in class JMenuItem
Returns:
the string "MenuUI"
See Also:
JComponent.getUIClassID(), UIDefaults.getUI(javax.swing.JComponent)

setModel

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

Overrides:
setModel in class AbstractButton
Parameters:
newModel - the ButtonModel
See Also:
AbstractButton.getModel()

isSelected

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

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

setSelected

public void setSelected(boolean b)
Enabled: 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

isPopupMenuVisible

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

Returns:
true if the menu is visible, else false

setPopupMenuVisible

public void setPopupMenuVisible(boolean b)
Enabled: 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

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
Since:
1.3

getDelay

public int getDelay()
Enabled: 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

setDelay

public void setDelay(int d)
Enabled: 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

ensurePopupMenuCreated

private void ensurePopupMenuCreated()

getCustomMenuLocation

private Point getCustomMenuLocation()

setMenuLocation

public void setMenuLocation(int x,
                            int y)
Enabled: 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

add

public JMenuItem add(JMenuItem menuItem)
Enabled: 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 Component add(Component c)
Enabled: 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
See Also:
Container.addImpl(java.awt.Component, java.lang.Object, int), Container.validate(), #revalidate

add

public Component add(Component c,
                     int index)
Enabled: 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
See Also:
remove(javax.swing.JMenuItem), java.awt.Container#add(Component, int)

add

public JMenuItem add(String s)
Enabled: 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

add

public JMenuItem add(Action a)
Enabled: Creates a new menu item attached to the specified Action object and appends it to the end of this menu. As of 1.3, this is no longer the preferred method for adding Actions to a container. Instead it is recommended to configure a control with an action using setAction, and then add that control directly to the Container.

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

createActionComponent

protected JMenuItem createActionComponent(Action a)
Factory method which creates the JMenuItem for Actions added to the JMenu. As of 1.3, this is no longer the preferred method. Instead it is recommended to configure a control with an action using setAction, and then adding that control directly to the Container.

Parameters:
a - the Action for the menu item to be added
Returns:
the new menu item
Since:
1.3
See Also:
Action

createActionChangeListener

protected java.beans.PropertyChangeListener createActionChangeListener(JMenuItem b)
Returns a properly configured PropertyChangeListener which updates the control as changes to the Action occur. As of 1.3, this is no longer the preferred method for adding Actions to a Container. Instead it is recommended to configure a control with an action using setAction, and then add that control directly to the Container.


addSeparator

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


insert

public void insert(String s,
                   int pos)
Enabled: 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

insert

public JMenuItem insert(JMenuItem mi,
                        int pos)
Enabled: 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 JMenuItem insert(Action a,
                        int pos)
Enabled: 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

insertSeparator

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

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

getItem

public JMenuItem getItem(int pos)
Suppressed: 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()
Enabled: 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
See Also:
getMenuComponentCount()

isTearOff

public boolean isTearOff()
Enabled: 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

remove

public void remove(JMenuItem item)
Suppressed: 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

remove

public void remove(int pos)
Enabled: 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
See Also:
Container.add(java.awt.Component)

remove

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

Overrides:
remove in class Container
Parameters:
c - the component to be removed
See Also:
Container.add(java.awt.Component)

removeAll

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

Overrides:
removeAll in class Container
See Also:
Container.add(java.awt.Component), Container.remove(int)

getMenuComponentCount

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

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

getMenuComponent

public Component getMenuComponent(int n)
Enabled: 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

getMenuComponents

public Component[] getMenuComponents()
Enabled: 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

isTopLevelMenu

public boolean isTopLevelMenu()
Enabled: 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

isMenuComponent

public boolean isMenuComponent(Component c)
Enabled: 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

translateToPopupMenu

private Point translateToPopupMenu(Point p)

translateToPopupMenu

private Point translateToPopupMenu(int x,
                                   int y)

getPopupMenu

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


addMenuListener

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

Parameters:
l - the listener to be added

removeMenuListener

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

Parameters:
l - the listener to be removed

getMenuListeners

public MenuListener[] getMenuListeners()
Suppressed: 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
Since:
1.4

fireMenuSelected

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

See Also:
EventListenerList

fireMenuDeselected

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

See Also:
EventListenerList

fireMenuCanceled

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

See Also:
EventListenerList

configurePropertiesFromAction

protected void configurePropertiesFromAction(Action a)
Factory method which sets the ActionEvent source's properties according to values from the Action instance. The properties which are set may differ for subclasses. By default, the properties which get set are Text, Icon, Enabled, ToolTipText, ActionCommand, and Mnemonic.

Overrides:
configurePropertiesFromAction in class JMenuItem
Parameters:
a - the Action from which to get the properties, or null
Since:
1.4
See Also:
Action, AbstractButton.setAction(javax.swing.Action)

createMenuChangeListener

private ChangeListener createMenuChangeListener()

createWinListener

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

Parameters:
p - the JPopupMenu
Returns:
the new window-closing listener
See Also:
WinListener

menuSelectionChanged

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

Specified by:
menuSelectionChanged in interface MenuElement
Overrides:
menuSelectionChanged in class JMenuItem
Parameters:
isIncluded - true if this menu is active, false if it is not
See Also:
MenuSelectionManager.setSelectedPath(MenuElement[])

getSubElements

public MenuElement[] getSubElements()
Enabled: 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.

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

getComponent

public Component getComponent()
Enabled: 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.

Specified by:
getComponent in interface MenuElement
Overrides:
getComponent in class JMenuItem
Returns:
the Component value

applyComponentOrientation

public void applyComponentOrientation(ComponentOrientation o)
Suppressed: Sets the ComponentOrientation property of this menu and all components contained within it. This includes all components returned by getMenuComponents.

Overrides:
applyComponentOrientation in class Container
Since:
1.4
See Also:
java.awt.Component#setComponentOrientation, java.awt.Component#getComponentOrientation

setComponentOrientation

public void setComponentOrientation(ComponentOrientation o)
Suppressed:

Overrides:
setComponentOrientation in class Component
See Also:
ComponentOrientation

setAccelerator

public void setAccelerator(KeyStroke keyStroke)
Enabled: 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

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
See Also:
java.awt.event.KeyEvent, java.awt.event.KeyListener, Component.addKeyListener(java.awt.event.KeyListener), Component.enableEvents(long), Component.isShowing()

doClick

public void doClick(int pressTime)
Suppressed: 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

buildMenuElementArray

private MenuElement[] buildMenuElementArray(JMenu leaf)

writeObject

private void writeObject(ObjectOutputStream s)
                  throws IOException
See readObject and writeObject in JComponent for more information about serialization in Swing.

Parameters:
s - the ObjectOutputStream in which to write
IOException

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.

getAccessibleContext

public AccessibleContext getAccessibleContext()
Suppressed: 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.

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


comments?