| JavaTM 2 Platform Std. Ed. v1.6.0
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:
- ImageObserver, ItemSelectable, MenuContainer, Serializable, Accessible, MenuElement, SwingConstants
public class JMenu - extends JMenuItem
- implements Accessible, MenuElement
An implementation of a menu -- a popup window containing
JMenuItems that
is displayed when the user selects an item on the JMenuBar.
In addition to JMenuItems, a JMenu can
also contain JSeparators.
In essence, a menu is a button with an associated JPopupMenu.
When the "button" is pressed, the JPopupMenu appears. If the
"button" is on the JMenuBar, the menu is a top-level window.
If the "button" is another menu item, then the JPopupMenu is
"pull-right" menu.
Menus can be configured, and to some degree controlled, by
Actions. Using an
Action with a menu has many benefits beyond directly
configuring a menu. Refer to
Swing Components Supporting Action for more
details, and you can find more information in How
to Use Actions, a section in The Java Tutorial.
For information and examples of using menus see
How to Use Menus,
a section in The Java Tutorial.
Warning: Swing is not thread safe. For more
information see Swing's Threading
Policy.
Warning:
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeansTM
has been added to the java.beans package.
Please see XMLEncoder.
- See Also:
JMenuItem,
JSeparator,
JMenuBar,
JPopupMenu
|
Nested Class Summary |
protected class |
JMenu.AccessibleJMenu
This class implements accessibility support for the
JMenu class. |
protected class |
JMenu.WinListener
A listener class that watches for a popup window closing. |
| 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 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()
Constructs a new JMenu with no text. |
JMenu(Action a)
Constructs a menu whose properties are taken from the
Action supplied. |
JMenu(String s)
Constructs a new JMenu with the supplied string
as its text. |
JMenu(String s,
boolean b)
Constructs a new JMenu with the supplied string as
its text and specified as a tear-off menu or not. |
|
Method Summary |
JMenuItem |
add(Action a)
Creates a new menu item attached to the specified
Action object and appends it to the end of this menu. |
Component |
add(Component c)
Appends a component to the end of this menu. |
Component |
add(Component c,
int index)
Adds the specified component to this container at the given
position. |
JMenuItem |
add(JMenuItem menuItem)
Appends a menu item to the end of this menu. |
JMenuItem |
add(String s)
Creates a new menu item with the specified text and appends
it to the end of this menu. |
void |
addMenuListener(MenuListener l)
Adds a listener for menu events. |
void |
addSeparator()
Appends a new separator to the end of the menu. |
void |
applyComponentOrientation(ComponentOrientation o)
Sets the ComponentOrientation property of this menu
and all components contained within it. |
protected 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. |
protected JMenu.WinListener |
createWinListener(JPopupMenu p)
Creates a window-closing listener for the popup. |
void |
doClick(int pressTime)
Programmatically performs a "click". |
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()
Gets the AccessibleContext associated with this JMenu. |
Component |
getComponent()
Returns the java.awt.Component used to
paint this MenuElement. |
int |
getDelay()
Returns the suggested delay, in milliseconds, before submenus
are popped up or down. |
JMenuItem |
getItem(int pos)
Returns the JMenuItem at the specified position. |
int |
getItemCount()
Returns the number of items on the menu, including separators. |
Component |
getMenuComponent(int n)
Returns the component at position n. |
int |
getMenuComponentCount()
Returns the number of components on the menu. |
Component[] |
getMenuComponents()
Returns an array of Components of the menu's
subcomponents. |
MenuListener[] |
getMenuListeners()
Returns an array of all the MenuListeners added
to this JMenu with addMenuListener(). |
JPopupMenu |
getPopupMenu()
Returns the popupmenu associated with this menu. |
protected Point |
getPopupMenuOrigin()
Computes the origin for the JMenu's popup menu. |
MenuElement[] |
getSubElements()
Returns an array of MenuElements containing the submenu
for this menu component. |
String |
getUIClassID()
Returns the name of the L&F class that renders this component. |
JMenuItem |
insert(Action a,
int pos)
Inserts a new menu item attached to the specified Action
object at a given position. |
JMenuItem |
insert(JMenuItem mi,
int pos)
Inserts the specified JMenuitem at a given position. |
void |
insert(String s,
int pos)
Inserts a new menu item with the specified text at a
given position. |
void |
insertSeparator(int index)
Inserts a separator at the specified position. |
boolean |
isMenuComponent(Component c)
Returns true if the specified component exists in the
submenu hierarchy. |
boolean |
isPopupMenuVisible()
Returns true if the menu's popup window is visible. |
boolean |
isSelected()
Returns true if the menu is currently selected (highlighted). |
boolean |
isTearOff()
Returns true if the menu can be torn off. |
boolean |
isTopLevelMenu()
Returns true if the menu is a 'top-level menu', that is, if it is
the direct child of a menubar. |
void |
menuSelectionChanged(boolean isIncluded)
Messaged when the menubar selection changes to activate or
deactivate this menu. |
protected String |
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)
Removes the component c from this menu. |
void |
remove(int pos)
Removes the menu item at the specified index from this menu. |
void |
remove(JMenuItem item)
Removes the specified menu item from this menu. |
void |
removeAll()
Removes all menu items from this menu. |
void |
removeMenuListener(MenuListener l)
Removes a listener for menu events. |
void |
setAccelerator(KeyStroke keyStroke)
setAccelerator is not defined for JMenu. |
void |
setComponentOrientation(ComponentOrientation o)
Sets the language-sensitive orientation that is to be used to order
the elements or text within this component. |
void |
setDelay(int d)
Sets the suggested delay before the menu's PopupMenu
is popped up or down. |
void |
setMenuLocation(int x,
int y)
Sets the location of the popup component. |
void |
setModel(ButtonModel newModel)
Sets the data model for the "menu button" -- the label
that the user clicks to open or close the menu. |
void |
setPopupMenuVisible(boolean b)
Sets the visibility of the menu's popup. |
void |
setSelected(boolean b)
Sets the selection status of the menu. |
void |
updateUI()
Resets the UI property with a value from the current look and feel. |
| Methods inherited from class javax.swing.JMenuItem |
actionPropertyChanged, addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, 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, createActionPropertyChangeListener, createChangeListener, createItemListener, doClick, fireActionPerformed, fireItemStateChanged, fireStateChanged, getAction, getActionCommand, getActionListeners, getChangeListeners, getDisabledIcon, getDisabledSelectedIcon, getDisplayedMnemonicIndex, getHideActionText, getHorizontalAlignment, getHorizontalTextPosition, getIcon, getIconTextGap, getItemListeners, getLabel, getMargin, getMnemonic, getModel, getMultiClickThreshhold, getPressedIcon, getRolloverIcon, getRolloverSelectedIcon, getSelectedIcon, getSelectedObjects, getText, getUI, getVerticalAlignment, getVerticalTextPosition, imageUpdate, isBorderPainted, isContentAreaFilled, isFocusPainted, isRolloverEnabled, paintBorder, removeActionListener, removeChangeListener, removeItemListener, removeNotify, setAction, setActionCommand, setBorderPainted, setContentAreaFilled, setDisabledIcon, setDisabledSelectedIcon, setDisplayedMnemonicIndex, setFocusPainted, setHideActionText, 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, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
| Methods inherited from class java.awt.Container |
add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, 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, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
popupListener
protected JMenu.WinListener popupListener
- The window-closing listener for the popup.
- See Also:
JMenu.WinListener
JMenu
public JMenu()
- Constructs a new
JMenu with no text.
JMenu
public JMenu(String s)
- Constructs a new
JMenu with the supplied string
as its text.
- Parameters:
s - the text for the menu label
JMenu
public JMenu(Action a)
- 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)
- 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 labelb - can the menu be torn off (not yet implemented)
updateUI
public void updateUI()
- 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()
- 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)
- Sets the data model for the "menu button" -- the label
that the user clicks to open or close the menu.
- Over
|