public class JMenu extends JMenuItem implements Accessible, MenuElement
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.
| Modifier and Type | Class and Description |
|---|---|
protected class |
JMenu.AccessibleJMenu
Implements support for assisitive technologies for
JMenu. |
protected class |
JMenu.WinListener |
JMenuItem.AccessibleJMenuItemAbstractButton.AccessibleAbstractButton, AbstractButton.ButtonChangeListenerJComponent.AccessibleJComponentContainer.AccessibleAWTContainerComponent.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy| Modifier and Type | Field and Description |
|---|---|
protected JMenu.WinListener |
popupListener |
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_PROPERTYaccessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWBOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTBOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WESTABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH| Constructor and Description |
|---|
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. |
| Modifier and Type | Method and Description |
|---|---|
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.
|
addMenuDragMouseListener, addMenuKeyListener, configurePropertiesFromAction, createActionPropertyChangeListener, fireMenuDragMouseDragged, fireMenuDragMouseEntered, fireMenuDragMouseExited, fireMenuDragMouseReleased, fireMenuKeyPressed, fireMenuKeyReleased, fireMenuKeyTyped, getAccelerator, getMenuDragMouseListeners, getMenuKeyListeners, init, isArmed, processKeyEvent, processMenuDragMouseEvent, processMenuKeyEvent, processMouseEvent, removeMenuDragMouseListener, removeMenuKeyListener, setArmed, setEnabled, setUIaddActionListener, 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, setVerticalTextPositionaddAncestorListener, 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, updateadd, 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, validateTreeaction, 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, transferFocusUpCycleclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitprocessKeyEvent, processMouseEventprotected JMenu.WinListener popupListener
public JMenu()
public JMenu(String text)
JMenu with the specified label.text - label for this menupublic JMenu(Action action)
JMenu object.action - Action that is used to create menu item tha will be
added to the menu.public JMenuItem add(JMenuItem item)
item - Menu item to add to this menupublic Component add(Component component, int index)
public JMenuItem add(String text)
text - label for the menu item that will be addedpublic JMenuItem add(Action action)
action - action to construct the menu item withpublic void remove(JMenuItem item)
item - Menu Item which needs to be removedpublic void remove(int index)
public void removeAll()
public void insert(String text, int index)
text - label for the new menu itemindex - index at which to insert newly created menu item.public JMenuItem insert(JMenuItem item, int index)
item - menu item to insertindex - index at which to insert menu item.public JMenuItem insert(Action action, int index)
action - Action for the new menu itemindex - index at which to insert newly created menu item.public void updateUI()
public String getUIClassID()
getUIClassID in class JMenuItemJComponent.setUI(javax.swing.plaf.ComponentUI),
JComponent.updateUI()public void setModel(ButtonModel model)
setModel in class AbstractButtonmodel - model to setpublic boolean isSelected()
isSelected in class AbstractButtonpublic void setSelected(boolean selected)
setSelected in class AbstractButtonselected - true if the menu should be selected and false otherwisepublic boolean isPopupMenuVisible()
public void setPopupMenuVisible(boolean popup)
popup - true if popup should be visible and false otherwiseprotected Point getPopupMenuOrigin()
public int getDelay()
public void setDelay(int delay)
delay - number of milliseconds before
popup menu associated with the menu appears or disappears after
menu was selected or deselected respectivelypublic void setMenuLocation(int x, int y)
x - x-coordinate of the menu locationy - y-coordinate of the menu locationprotected JMenuItem createActionComponent(Action action)
action - Action to use for creation of JMenuItemprotected PropertyChangeListener createActionChangeListener(JMenuItem item)
item - menu that contains action to listen topublic void addSeparator()
public void insertSeparator(int index)
index - Index at which separator should be insertedpublic JMenuItem getItem(int index)
index - Index at which to look for the menu itempublic int getItemCount()
getMenuComponentCount()public boolean isTearOff()
public int getMenuComponentCount()
public Component getMenuComponent(int index)
index - index at which to get the menu component in the menupublic Component[] getMenuComponents()
public boolean isTopLevelMenu()
public boolean isMenuComponent(Component component)
component - Component to look forpublic JPopupMenu getPopupMenu()
public void addMenuListener(MenuListener listener)
listener - MenuListener to addpublic void removeMenuListener(MenuListener listener)
listener - MenuListener to removepublic MenuListener[] getMenuListeners()
MenuListener objects.protected void fireMenuSelected()
protected void fireMenuDeselected()
protected void fireMenuCanceled()
protected JMenu.WinListener createWinListener(JPopupMenu popup)
popup - JPopupMenu to listen topublic void menuSelectionChanged(boolean changed)
menuSelectionChanged in interface MenuElementmenuSelectionChanged in class JMenuItemchanged - true if the menu was selected and false otherwisepublic MenuElement[] getSubElements()
getSubElements in interface MenuElementgetSubElements in class JMenuItempublic Component getComponent()
JMenuItemgetComponent in interface MenuElementgetComponent in class JMenuItempublic void setAccelerator(KeyStroke keystroke)
setAccelerator in class JMenuItemkeystroke - accelerator for this menuprotected void processKeyEvent(KeyEvent event)
processKeyEvent in class JComponentevent - The KeyEventKeyListener,
Component.addKeyListener(KeyListener),
Component.enableEvents(long)public void doClick(int time)
doClick in class AbstractButtontime - Number of milliseconds for which this menu stays pressedprotected String paramString()
paramString in class JMenuItempublic AccessibleContext getAccessibleContext()
JMenuItemJMenuItem component.getAccessibleContext in interface AccessiblegetAccessibleContext in class JMenuItemJMenuItem.AccessibleJMenuItem).