javax.swing
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.
Nested Class Summary | |
---|---|
protected class | JMenu.AccessibleJMenu
Implements support for assisitive technologies for JMenu . |
protected class | JMenu.WinListener |
Field Summary | |
---|---|
protected JMenu.WinListener | popupListener |
Constructor Summary | |
---|---|
JMenu()
Creates a new JMenu object. | |
JMenu(String text)
Creates a new JMenu with the specified label.
| |
JMenu(Action action)
Creates a new JMenu object.
| |
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(JMenuItem item)
Adds specified menu item to this menu
|
Component | add(Component component)
Adds specified component to this menu.
|
Component | add(Component component, int index)
Adds specified component to this menu at the given index
|
JMenuItem | add(String text)
Adds JMenuItem constructed with the specified label to this menu
|
JMenuItem | add(Action action)
Adds JMenuItem constructed using properties from specified action.
|
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() |
Component | getComponent() |
int | getDelay()
Returns delay property.
|
JMenuItem | getItem(int index)
Returns menu item located at the specified index in the menu
|
int | getItemCount()
Returns number of items in the menu including separators.
|
Component | getMenuComponent(int index)
Returns menu component located at the givent index
in the menu
|
int | getMenuComponentCount()
Returns number of menu components in this menu
|
Component[] | getMenuComponents()
Return components belonging to this menu
|
MenuListener[] | getMenuListeners()
Returns all registered MenuListener objects.
|
JPopupMenu | getPopupMenu()
Returns popup menu associated with the menu.
|
protected Point | getPopupMenuOrigin()
Returns origin point of the popup menu. |
MenuElement[] | getSubElements()
Method of MenuElement interface. |
String | getUIClassID()
This method returns a name to identify which look and feel class will be
the UI delegate for the menu.
|
void | insert(String text, int index)
Creates JMenuItem with the specified text and inserts it in the
at the specified index
|
JMenuItem | insert(JMenuItem item, int index)
Creates JMenuItem with the specified text and inserts it in the
at the specified index. |
JMenuItem | insert(Action action, int index)
Creates JMenuItem with the associated action and inserts it to the menu
at the specified index. |
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(JMenuItem item)
Removes given menu item from this menu. |
void | remove(int index)
Removes component at the specified index from this menu
|
void | remove(Component component)
Removes given component 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. |
JMenu
with the specified label.
Parameters: text label for this menu
JMenu
object.
Parameters: action Action that is used to create menu item tha will be added to the menu.
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
Parameters: item Menu item to add to this menu
Returns: Menu item that was added
Parameters: component Component to add to this menu
Returns: Component that was added
Parameters: component Component to add index Position of this menu item in the menu
Returns: Component that was added
Parameters: text label for the menu item that will be added
Returns: Menu Item that was added to this menu
Parameters: action action to construct the menu item with
Returns: Menu Item that was added to this menu
Parameters: listener MenuListener to add
Parameters: item menu that contains action to listen to
Returns: The PropertyChangeListener
Parameters: action Action to use for creation of JMenuItem
Returns: JMenuItem that was creted with given action
Parameters: popup JPopupMenu to listen to
Returns: The WinListener
Parameters: time Number of milliseconds for which this menu stays pressed
Returns: Returns reference to itself
Returns: delay property, indicating number of milliseconds before popup menu associated with the menu appears or disappears after menu was selected or deselected respectively
Parameters: index Index at which to look for the menu item
Returns: menu item located at the specified index in the menu
Returns: number of items in the menu
See Also: getMenuComponentCount
Parameters: index index at which to get the menu component in the menu
Returns: Menu Component located in the menu at the specified index
Returns: number of menu components in this menu
Returns: components belonging to this menu
MenuListener
objects.
Returns: an array of listeners
Since: 1.4
Returns: popup menu associated with the menu.
Returns: the origin of the popup menu
Returns: array containing popupMenu that is associated with this menu
Returns: The Look and Feel classID. "MenuUI"
Parameters: text label for the new menu item index index at which to insert newly created menu item.
Parameters: item menu item to insert index index at which to insert menu item.
Returns: Menu item that was added to the menu
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
Parameters: index Index at which separator should be inserted
Parameters: component Component to look for
Returns: true if the given component exists in this menu, and false otherwise
Returns: true if the popup associated with this menu is currently visible on the screen and false otherwise.
Returns: true if the menu is selected and false otherwise
Returns: true if this menu is a tear-off menu and false otherwise
Returns: true if this menu is top level menu, and false otherwise
Parameters: changed true if the menu was selected and false otherwise
Returns: A string describing this JMenu
Parameters: event The KeyEvent
Parameters: item Menu Item which needs to be removed
Parameters: index Position of the component that needs to be removed in the menu
Parameters: component Component to remove
Parameters: listener MenuListener to remove
Parameters: keystroke accelerator for this menu
Parameters: delay number of milliseconds before popup menu associated with the menu appears or disappears after menu was selected or deselected respectively
Parameters: x x-coordinate of the menu location y y-coordinate of the menu location
Parameters: model model to set
Parameters: popup true if popup should be visible and false otherwise
Parameters: selected true if the menu should be selected and false otherwise