|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.AbstractButton
javax.swing.JMenuItem
javax.swing.JMenu
public class JMenu
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.
| 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.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 java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface javax.swing.MenuElement |
|---|
processKeyEvent, processMouseEvent |
| Field Detail |
|---|
protected JMenu.WinListener popupListener
| Constructor Detail |
|---|
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 JMenu(String text,
boolean tearoff)
JMenu with specified label and an option
for this menu to be tear-off menu.
text - label for this menutearoff - true if this menu should be tear-off and false otherwise| Method Detail |
|---|
public JMenuItem add(JMenuItem item)
item - Menu item to add to this menu
public Component add(Component component)
add in class Containercomponent - Component to add to this menu
public Component add(Component component,
int index)
add in class Containercomponent - Component to addindex - Position of this menu item in the menu
public JMenuItem add(String text)
text - label for the menu item that will be added
public JMenuItem add(Action action)
action - action to construct the menu item with
public void remove(JMenuItem item)
item - Menu Item which needs to be removedpublic void remove(int index)
remove in class Containerindex - Position of the component that needs to be removed in the menupublic void remove(Component component)
remove in class Containercomponent - Component to removepublic void removeAll()
removeAll in class Container
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()
updateUI in class JMenuItempublic 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 respectively
public 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 JMenuItem
protected PropertyChangeListener createActionChangeListener(JMenuItem item)
item - menu that contains action to listen to
public 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 item
public 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 menu
public Component[] getMenuComponents()
public boolean isTopLevelMenu()
public boolean isMenuComponent(Component component)
component - Component to look for
public 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 to
public 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()
JMenuItem
getComponent 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).
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||