|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | 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
An implementation of a menu -- a popup window containing JMenuItem
s that
is displayed when the user selects an item on the JMenuBar
. In addition
to JMenuItems, a JMenu can also contain JSeparator
s.
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 the keyboard keys used by this component in the standard Look and Feel (L&F) renditions, see the JMenu key assignments.
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. A future release of Swing will provide support for long term persistence.
JMenuItem
,
JSeparator
,
JMenuBar
,
JPopupMenu
, Serialized FormInner Class Summary | |
protected class |
JMenu.AccessibleJMenu
The class used to obtain the accessible role for this object. |
protected class |
JMenu.WinListener
A listener class that watches for a popup window closing. |
Inner classes inherited from class javax.swing.JMenuItem |
JMenuItem.AccessibleJMenuItem |
Inner classes inherited from class javax.swing.AbstractButton |
AbstractButton.AccessibleAbstractButton,
AbstractButton.ButtonChangeListener |
Inner classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
Field Summary | |
protected JMenu.WinListener |
popupListener
The window-closing listener for the popup. |
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 |
Constructor Summary | |
JMenu()
Creates a new JMenu with no text. |
|
JMenu(String s)
Creates a new JMenu with the supplied string as its text |
|
JMenu(String s,
boolean b)
Creates 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 menuitem 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. |
JMenuItem |
add(JMenuItem menuItem)
Appends a menuitem to the end of this menu. |
JMenuItem |
add(String s)
Creates a new menuitem with the specified text and appends it to the end of this menu. |
void |
addMenuListener(MenuListener l)
Add a listener for menu events |
void |
addSeparator()
Append a new separator to the end of the menu. |
protected PropertyChangeListener |
createActionChangeListener(JMenuItem b)
|
protected JMenu.WinListener |
createWinListener(JPopupMenu p)
Create a window-closing listener for the popup. |
void |
doClick(int pressTime)
Programatically perform a "click". |
protected void |
fireMenuCanceled()
Notify all listeners that have registered interest for notification on this event type. |
protected void |
fireMenuDeselected()
Notify all listeners that have registered interest for notification on this event type. |
protected void |
fireMenuSelected()
Notify all listeners that have registered interest for notification on this event type. |
AccessibleContext |
getAccessibleContext()
Get the AccessibleContext associated with this JComponent |
Component |
getComponent()
This method returns the java.awt.Component used to paint this MenuElement. |
int |
getDelay()
Returns the suggested delay before the menu's PopupMenu is 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 the menu's subcomponents |
JPopupMenu |
getPopupMenu()
Returns the popupmenu associated with this menu |
MenuElement[] |
getSubElements()
Returns an array containing the sub-menu components for this menu component |
String |
getUIClassID()
Returns the name of the L&F class that renders this component. |
JMenuItem |
insert(Action a,
int pos)
Insert a new menuitem attached to the specified Action object at a given position. |
JMenuItem |
insert(JMenuItem mi,
int pos)
Insert the specified JMenuitem at a given position. |
void |
insert(String s,
int pos)
Insert a new menuitem 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 (popped up). |
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 e)
Override processKeyEvent to process events |
void |
remove(Component c)
Removes the Component 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()
Remove all menu items from this menu. |
void |
removeMenuListener(MenuListener l)
Remove a listener for menu events |
void |
setAccelerator(KeyStroke keyStroke)
setAccelerator() is not defined for JMenu. |
void |
setDelay(int d)
Sets the suggested delay before the menu's PopupMenu is popped up or down. |
void |
setMenuLocation(int x,
int y)
Set the location of the popup component |
void |
setModel(ButtonModel newModel)
Set the data model for the "menu button" -- the label that the user clicks to open or close the menu. |
void |
setPopupMenuVisible(boolean b)
Set the visibility of the Menu's popup portion. |
void |
setSelected(boolean b)
Sets the selection status of the menu. |
void |
updateUI()
Notification from the UIFactory that the L&F has changed. |
Methods inherited from class java.awt.Container |
add,
add,
add,
add,
addContainerListener,
addImpl,
countComponents,
deliverEvent,
doLayout,
findComponentAt,
findComponentAt,
getComponent,
getComponentAt,
getComponentAt,
getComponentCount,
getComponents,
getLayout,
insets,
invalidate,
isAncestorOf,
layout,
list,
list,
locate,
minimumSize,
paintComponents,
preferredSize,
print,
printComponents,
processContainerEvent,
processEvent,
removeContainerListener,
setCursor,
setLayout,
validate,
validateTree |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected JMenu.WinListener popupListener
JMenu.WinListener
Constructor Detail |
public JMenu()
public JMenu(String s)
s
- The text for the menu labelpublic JMenu(String s, boolean b)
s
- The text for the menu labelb
- can the menu be torn off (not yet implemented)Method Detail |
public void updateUI()
JComponent.updateUI()
public String getUIClassID()
JComponent.getUIClassID()
,
UIDefaults.getUI(javax.swing.JComponent)
public void setModel(ButtonModel newModel)
m
- the ButtonModelAbstractButton.getModel()
public boolean isSelected()
public void setSelected(boolean b)
b
- a boolean value -- true to select the menu and
open it, false to unselect the menu and close itpublic boolean isPopupMenuVisible()
public void setPopupMenuVisible(boolean b)
b
- a boolean value -- true to make the menu visible,
false to hide itpublic int getDelay()
public void setDelay(int d)
d
- the number of milliseconds to delayd
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 positionpublic JMenuItem add(JMenuItem menuItem)
menuItem
- the JMenuitem to be addedpublic Component add(Component c)
c
- the Component to addpublic JMenuItem add(String s)
s
- the string for the menuitem to be addedpublic JMenuItem add(Action a)
a
- the Action for the menuitem to be addedAction
protected PropertyChangeListener createActionChangeListener(JMenuItem b)
public void addSeparator()
public void insert(String s, int pos)
s
- the text for the menuitem to addpos
- an int giving the position at which to add the
new menuitempublic JMenuItem insert(JMenuItem mi, int pos)
mi
- the JMenuitem to addpos
- an int giving the position at which to add the
new JMenuitempublic JMenuItem insert(Action a, int pos)
a
- the Action object for the menuitem to addpos
- an int giving the position at which to add the
new menuitempublic void insertSeparator(int index)
index
- an int giving the position at which to
insert the menu separatorindex
is less than 0.public JMenuItem getItem(int pos)
pos
- an int giving the positionindex
is less than 0.public int getItemCount()
getMenuComponentCount()
public boolean isTearOff()
public void remove(JMenuItem item)
item
- the JMenuItem to be removed from the menupublic void remove(int pos)
index
- the position of the item to be removed.index
is less than 0.public void remove(Component c)
c
- the component to be removedpublic void removeAll()
Container.add(java.awt.Component)
,
Container.remove(int)
public int getMenuComponentCount()
public Component getMenuComponent(int n)
n
- the position of the component to be returnedpublic Component[] getMenuComponents()
public boolean isTopLevelMenu()
public boolean isMenuComponent(Component c)
c
- the Component to be testedpublic JPopupMenu getPopupMenu()
public void addMenuListener(MenuListener l)
l
- the listener to be addedpublic void removeMenuListener(MenuListener l)
l
- the listener to be removedprotected void fireMenuSelected()
EventListenerList
protected void fireMenuDeselected()
EventListenerList
protected void fireMenuCanceled()
EventListenerList
protected JMenu.WinListener createWinListener(JPopupMenu p)
p
- the JPopupMenuJMenu.WinListener
public void menuSelectionChanged(boolean isIncluded)
JMenuItem.menuSelectionChanged
.isIncluded
- true if this menu is active, false if
it is notpublic MenuElement[] getSubElements()
public Component getComponent()
public void setAccelerator(KeyStroke keyStroke)
keyStroke
- the KeyStroke which will serve as an acceleratorprotected void processKeyEvent(KeyEvent e)
e
- the key event.KeyEvent
,
KeyListener
,
Component.addKeyListener(java.awt.event.KeyListener)
,
Component.enableEvents(long)
public void doClick(int pressTime)
protected String paramString()
null
.public AccessibleContext getAccessibleContext()
|
JavaTM 2 Platform Standard Edition |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |