|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object![]()
![]()
![]()
java.awt.Component
![]()
![]()
![]()
java.awt.Container
![]()
![]()
![]()
javax.swing.JComponent
![]()
![]()
![]()
javax.swing.AbstractButton
![]()
![]()
![]()
javax.swing.JMenuItem
![]()
![]()
![]()
javax.swing.JMenu
, ItemSelectable
, MenuContainer
, Serializable
, Accessible
, MenuElement
, SwingConstants

public class JMenu

, 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.
For information and examples of using menus see How to Use Menus, a section in The Java Tutorial.
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
.
JMenuItem
,
JSeparator
,
JMenuBar
,
JPopupMenu
,
Serialized Form| 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. |
Nested classes/interfaces inherited from class javax.swing.JMenuItem ![]() |
|---|
JMenuItem.AccessibleJMenuItem |
Nested classes/interfaces inherited from class javax.swing.AbstractButton ![]() |
|---|
AbstractButton.AccessibleAbstractButton |
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 |
| Field Summary | |
|---|---|
protected JMenu.WinListener |
popupListener
The window-closing listener for the popup. |
Fields inherited from class javax.swing.JComponent ![]() |
|---|
accessibleContext |
Fields inherited from class java.awt.Component ![]() |
|---|
BOTTOM_ALIGNMENT |
Fields inherited from interface javax.swing.SwingConstants ![]() |
|---|
BOTTOM |
Fields inherited from interface java.awt.image.ImageObserver ![]() |
|---|
ABORT |
| Constructor Summary | |
|---|---|
JMenu
Constructs a new JMenu with no text. |
|
JMenu
Constructs a menu whose properties are taken from the Action supplied. |
|
JMenu
Constructs a new JMenu with the supplied string
as its text. |
|
JMenu
Constructs a new JMenu with the supplied string as
its text and specified as a tear-off menu or not. |
|
| Method Summary | |
|---|---|
JMenuItem |
add
Creates a new menu item attached to the specified Action object and appends it to the end of this menu. |
Component |
add
Appends a component to the end of this menu. |
Component |
add
Adds the specified component to this container at the given position. |
JMenuItem |
add
Appends a menu item to the end of this menu. |
JMenuItem |
add
Creates a new menu item with the specified text and appends it to the end of this menu. |
void |
addMenuListener
Adds a listener for menu events. |
void |
addSeparator
Appends a new separator to the end of the menu. |
void |
applyComponentOrientation
Sets the ComponentOrientation property of this menu
and all components contained within it. |
protected void |
configurePropertiesFromAction
Factory method which sets the ActionEvent
source's properties according to values from the
Action instance. |
protected PropertyChangeListener |
createActionChangeListener
Returns a properly configured PropertyChangeListener
which updates the control as changes to the Action occur. |
protected JMenuItem |
createActionComponent
Factory method which creates the JMenuItem for
Actions added to the JMenu. |
protected JMenu.WinListener |
createWinListener
Creates a window-closing listener for the popup. |
void |
doClick
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
Returns the JMenuItem at the specified position. |
int |
getItemCount
Returns the number of items on the menu, including separators. |
Component |
getMenuComponent
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
Inserts a new menu item attached to the specified Action
object at a given position. |
JMenuItem |
insert
Inserts the specified JMenuitem at a given position. |
void |
insert
Inserts a new menu item with the specified text at a given position. |
void |
insertSeparator
Inserts a separator at the specified position. |
boolean |
isMenuComponent
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
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
Processes key stroke events such as mnemonics and accelerators. |
void |
remove
Removes the component c from this menu. |
void |
remove
Removes the menu item at the specified index from this menu. |
void |
remove
Removes the specified menu item from this menu. |
void |
removeAll
Removes all menu items from this menu. |
void |
removeMenuListener
Removes a listener for menu events. |
void |
setAccelerator
setAccelerator is not defined for JMenu. |
void |
setComponentOrientation
Sets the language-sensitive orientation that is to be used to order the elements or text within this component. |
void |
setDelay
Sets the suggested delay before the menu's PopupMenu
is popped up or down. |
void |
setMenuLocation
Sets the location of the popup component. |
void |
setModel
Sets the data model for the "menu button" -- the label that the user clicks to open or close the menu. |
void |
setPopupMenuVisible
Sets the visibility of the menu's popup. |
void |
setSelected
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 java.lang.Object ![]() |
|---|
clone |
Methods inherited from interface javax.swing.MenuElement ![]() |
|---|
processKeyEvent |
| Field Detail |
|---|

protected JMenu.WinListener![]()
![]()
popupListener
JMenu.WinListener

| Constructor Detail |
|---|

public JMenu()
JMenu with no text.

public JMenu(String![]()
![]()
s)
JMenu with the supplied string
as its text.
s - the text for the menu label

public JMenu(Action![]()
![]()
a)
Action supplied.
a - an Action

public JMenu(String![]()
![]()
s, boolean b)
JMenu with the supplied string as
its text and specified as a tear-off menu or not.
s - the text for the menu labelb - can the menu be torn off (not yet implemented)| Method Detail |
|---|

public void updateUI()
updateUI

in class JMenuItem

JComponent.updateUI()


public String![]()
![]()
getUIClassID()
getUIClassID

in class JMenuItem

JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)


public void setModel(ButtonModel![]()
![]()
newModel)
setModel

in class AbstractButton

newModel - the ButtonModelAbstractButton.getModel()


public boolean isSelected()
isSelected

in class AbstractButton


public void setSelected(boolean b)
setSelected

in class AbstractButton

b - true to select (highlight) the menu; false to de-select
the menu

public boolean isPopupMenuVisible()

public void setPopupMenuVisible(boolean b)
b - a boolean value -- true to make the menu visible,
false to hide it

protected Point![]()
![]()
getPopupMenuOrigin()
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.
Point in the coordinate space of the
menu which should be used as the origin
of the JMenu's popup menu

public int getDelay()
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.
delay property

public void setDelay(int d)
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.
d - the number of milliseconds to delay
IllegalArgumentException

- if d
is less than 0

public void setMenuLocation(int x,
int y)
x - the x coordinate of the popup's new positiony - the y coordinate of the popup's new position

public JMenuItem![]()
![]()
add(JMenuItem
![]()
![]()
menuItem)
menuItem - the JMenuitem to be added
JMenuItem added

public Component![]()
![]()
add(Component
![]()
![]()
c)
add

in class Container

c - the Component to add
Component addedContainer.addImpl(java.awt.Component, java.lang.Object, int)
,
Container.validate()
,
JComponent.revalidate()


public Component![]()
![]()
add(Component
![]()
![]()
c, int index)
index equals -1, the component will
be appended to the end.
add

in class Container

c - the Component to addindex - the position at which to insert the component
Component addedremove(javax.swing.JMenuItem)
,
Container.add(Component, int)


public JMenuItem![]()
![]()
add(String
![]()
![]()
s)
s - the string for the menu item to be added

public JMenuItem![]()
![]()
add(Action
![]()
![]()
a)
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.
a - the Action for the menu item to be addedAction


protected JMenuItem![]()
![]()
createActionComponent(Action
![]()
![]()
a)
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.
a - the Action for the menu item to be added
Action


protected PropertyChangeListener![]()
![]()
createActionChangeListener(JMenuItem
![]()
![]()
b)
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.

public void addSeparator()

public void insert(String![]()
![]()
s, int pos)
s - the text for the menu item to addpos - an integer specifying the position at which to add the
new menu item
IllegalArgumentException

- when the value of
pos < 0

public JMenuItem![]()
![]()
insert(JMenuItem
![]()
![]()
mi, int pos)
JMenuitem at a given position.
mi - the JMenuitem to addpos - an integer specifying the position at which to add the
new JMenuitem
IllegalArgumentException

- if the value of
pos < 0

public JMenuItem![]()
![]()
insert(Action
![]()
![]()
a, int pos)
Action
object at a given position.
a - the Action object for the menu item to addpos - an integer specifying the position at which to add the
new menu item
IllegalArgumentException

- if the value of
pos < 0

public void insertSeparator(int index)
index - an integer specifying the position at which to
insert the menu separator
IllegalArgumentException

- if the value of
index < 0

public JMenuItem![]()
![]()
getItem(int pos)
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.
pos - an integer specifying the position
null
if the item as the specified position is not a menu item
IllegalArgumentException

- if the value of
pos < 0

public int getItemCount()
getMenuComponentCount()


public boolean isTearOff()
Error

- if invoked -- this method is not yet implemented

public void remove(JMenuItem![]()
![]()
item)
item - the JMenuItem to be removed from the menu

public void remove(int pos)
remove

in class Container

pos - the position of the item to be removed
IllegalArgumentException

- if the value of
pos < 0, or if pos
is greater than the number of menu itemsContainer.add(java.awt.Component)


public void remove(Component![]()
![]()
c)
c from this menu.
remove

in class Container

c - the component to be removedContainer.add(java.awt.Component)
,
Container.remove(int)


public void removeAll()
removeAll

in class Container

Container.add(java.awt.Component)
,
Container.remove(int)


public int getMenuComponentCount()

public Component![]()
![]()
getMenuComponent(int n)
n.
n - the position of the component to be returned
null
if there is no popup menu

public Component![]()
![]()
[] getMenuComponents()
Components of the menu's
subcomponents. Note that this returns all Components
in the popup menu, including separators.
Components or an empty array
if there is no popup menu

public boolean isTopLevelMenu()

public boolean isMenuComponent(Component![]()
![]()
c)
c - the Component to be tested
Component exists, false otherwise

public JPopupMenu![]()
![]()
getPopupMenu()

public void addMenuListener(MenuListener![]()
![]()
l)
l - the listener to be added

public void removeMenuListener(MenuListener![]()
![]()
l)
l - the listener to be removed

public MenuListener![]()
![]()
[] getMenuListeners()
MenuListeners added
to this JMenu with addMenuListener().
MenuListeners added or an empty
array if no listeners have been added

protected void fireMenuSelected()
Error

- if there is a null listenerEventListenerList


protected void fireMenuDeselected()
Error

- if there is a null listenerEventListenerList


protected void fireMenuCanceled()
Error

- if there is a null listenerEventListenerList


protected void configurePropertiesFromAction(Action![]()
![]()
a)
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.
configurePropertiesFromAction

in class JMenuItem

a - the Action from which to get the properties,
or nullAction
,
AbstractButton.setAction(javax.swing.Action)


protected JMenu.WinListener![]()
![]()
createWinListener(JPopupMenu
![]()
![]()
p)
p - the JPopupMenu
JMenu.WinListener


public void menuSelectionChanged(boolean isIncluded)
JMenuItem.menuSelectionChanged.
menuSelectionChanged

in interface MenuElement

menuSelectionChanged

in class JMenuItem

isIncluded - true if this menu is active, false if
it is notMenuSelectionManager.setSelectedPath(MenuElement[])


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

in interface MenuElement

getSubElements

in class JMenuItem

MenuElement objects

public Component![]()
![]()
getComponent()
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.
getComponent

in interface MenuElement

getComponent

in class JMenuItem

Component that paints this menu item

public void applyComponentOrientation(ComponentOrientation![]()
![]()
o)
ComponentOrientation property of this menu
and all components contained within it. This includes all
components returned by getMenuComponents
.
applyComponentOrientation

in class Container

o - the new component orientation of this menu and
the components contained within it.
NullPointerException

- if orientation is null.Component.setComponentOrientation(java.awt.ComponentOrientation)
,
Component.getComponentOrientation()


public void setComponentOrientation(ComponentOrientation![]()
![]()
o)
Component

LayoutManager and Component
subclasses will use this property to
determine how to lay out and draw components.
At construction time, a component's orientation is set to
ComponentOrientation.UNKNOWN,
indicating that it has not been specified
explicitly. The UNKNOWN orientation behaves the same as
ComponentOrientation.LEFT_TO_RIGHT.
To set the orientation of a single component, use this method.
To set the orientation of an entire component
hierarchy, use
applyComponentOrientation
.
setComponentOrientation

in class Component

ComponentOrientation


public void setAccelerator(KeyStroke![]()
![]()
keyStroke)
setAccelerator is not defined for JMenu.
Use setMnemonic instead.
setAccelerator

in class JMenuItem

keyStroke - the keystroke combination which will invoke
the JMenuItem's actionlisteners
without navigating the menu hierarchy
Error

- if invoked -- this method is not defined for JMenu.
Use setMnemonic instead

protected void processKeyEvent(KeyEvent![]()
![]()
evt)
processKeyEvent

in class JComponent

evt - the key event to be processedKeyEvent
,
KeyListener
,
KeyboardFocusManager
,
DefaultKeyboardFocusManager
,
Component.processEvent(java.awt.AWTEvent)
,
Component.dispatchEvent(java.awt.AWTEvent)
,
Component.addKeyListener(java.awt.event.KeyListener)
,
Component.enableEvents(long)
,
Component.isShowing()


public void doClick(int pressTime)
AbstractButton.doClick in order to make the menu pop up.
doClick

in class AbstractButton

pressTime - indicates the number of milliseconds the
button was pressed for

protected String![]()
![]()
paramString()
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.
paramString

in class JMenuItem


public AccessibleContext![]()
![]()
getAccessibleContext()
getAccessibleContext

in interface Accessible

getAccessibleContext

in class JMenuItem

|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||