|
|||||||||||
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
Safe:
Field Summary | |
private Point |
customMenuLocation
|
private static boolean |
DEBUG
|
private int |
delay
|
private static Hashtable |
listenerRegistry
|
private ChangeListener |
menuChangeListener
|
private MenuEvent |
menuEvent
|
protected javax.swing.JMenu.WinListener |
popupListener
The window-closing listener for the popup. |
private JPopupMenu |
popupMenu
|
private static boolean |
TRACE
|
private static String |
uiClassID
|
private static boolean |
VERBOSE
|
Fields inherited from class javax.swing.JMenuItem |
|
Fields inherited from class javax.swing.JComponent |
_bounds, accessibleContext, listenerList, paintingChild, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Container |
|
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 |
Constructor Summary | |
JMenu()
Enabled: Constructs a new JMenu with no text. |
|
JMenu(Action a)
Enabled: Constructs a menu whose properties are taken from the Action supplied. |
|
JMenu(String s)
Enabled: Constructs a new JMenu with the supplied string
as its text. |
|
JMenu(String s,
boolean b)
Enabled: Constructs 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)
Enabled: Creates a new menu item attached to the specified Action object and appends it to the end of this menu. |
Component |
add(Component c)
Enabled: Appends a component to the end of this menu. |
Component |
add(Component c,
int index)
Enabled: Adds the specified component to this container at the given position. |
JMenuItem |
add(JMenuItem menuItem)
Enabled: Appends a menu item to the end of this menu. |
JMenuItem |
add(String s)
Enabled: Creates a new menu item with the specified text and appends it to the end of this menu. |
void |
addMenuListener(MenuListener l)
Suppressed: Adds a listener for menu events. |
void |
addSeparator()
Enabled: Appends a new separator to the end of the menu. |
void |
applyComponentOrientation(ComponentOrientation o)
Suppressed: Sets the ComponentOrientation property of this menu
and all components contained within it. |
private MenuElement[] |
buildMenuElementArray(JMenu leaf)
|
protected void |
configurePropertiesFromAction(Action a)
Factory method which sets the ActionEvent
source's properties according to values from the
Action instance. |
protected java.beans.PropertyChangeListener |
createActionChangeListener(JMenuItem b)
Returns a properly configured PropertyChangeListener
which updates the control as changes to the Action occur. |
protected JMenuItem |
createActionComponent(Action a)
Factory method which creates the JMenuItem for
Action s added to the JMenu . |
private ChangeListener |
createMenuChangeListener()
|
protected javax.swing.JMenu.WinListener |
createWinListener(JPopupMenu p)
Creates a window-closing listener for the popup. |
void |
doClick(int pressTime)
Suppressed: Programmatically performs a "click". |
private void |
ensurePopupMenuCreated()
|
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()
Suppressed: Gets the AccessibleContext associated with this JMenu. |
Component |
getComponent()
Enabled: Returns the java.awt.Component used to
paint this MenuElement . |
private Point |
getCustomMenuLocation()
|
int |
getDelay()
Enabled: Returns the suggested delay, in milliseconds, before submenus are popped up or down. |
JMenuItem |
getItem(int pos)
Suppressed: Returns the JMenuItem at the specified position. |
int |
getItemCount()
Enabled: Returns the number of items on the menu, including separators. |
Component |
getMenuComponent(int n)
Enabled: Returns the component at position n . |
int |
getMenuComponentCount()
Enabled: Returns the number of components on the menu. |
Component[] |
getMenuComponents()
Enabled: Returns an array of Component s of the menu's
subcomponents. |
MenuListener[] |
getMenuListeners()
Suppressed: Returns an array of all the MenuListener s added
to this JMenu with addMenuListener(). |
JPopupMenu |
getPopupMenu()
Enabled: Returns the popupmenu associated with this menu. |
protected Point |
getPopupMenuOrigin()
Computes the origin for the JMenu 's popup menu. |
MenuElement[] |
getSubElements()
Enabled: Returns an array of MenuElement s containing the submenu
for this menu component. |
String |
getUIClassID()
Enabled: Returns the name of the L&F class that renders this component. |
(package private) void |
initFocusability()
Overriden to do nothing. |
JMenuItem |
insert(Action a,
int pos)
Enabled: Inserts a new menu item attached to the specified Action
object at a given position. |
JMenuItem |
insert(JMenuItem mi,
int pos)
Enabled: Inserts the specified JMenuitem at a given position. |
void |
insert(String s,
int pos)
Enabled: Inserts a new menu item with the specified text at a given position. |
void |
insertSeparator(int index)
Enabled: Inserts a separator at the specified position. |
boolean |
isMenuComponent(Component c)
Enabled: Returns true if the specified component exists in the submenu hierarchy. |
boolean |
isPopupMenuVisible()
Enabled: Returns true if the menu's popup window is visible. |
boolean |
isSelected()
Enabled: Returns true if the menu is currently selected (highlighted). |
boolean |
isTearOff()
Enabled: Returns true if the menu can be torn off. |
boolean |
isTopLevelMenu()
Enabled: 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)
Enabled: 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 evt)
Processes key stroke events such as mnemonics and accelerators. |
void |
remove(Component c)
Enabled: Removes the component c from this menu. |
void |
remove(int pos)
Enabled: Removes the menu item at the specified index from this menu. |
void |
remove(JMenuItem item)
Suppressed: Removes the specified menu item from this menu. |
void |
removeAll()
Enabled: Removes all menu items from this menu. |
void |
removeMenuListener(MenuListener l)
Enabled: Removes a listener for menu events. |
void |
setAccelerator(KeyStroke keyStroke)
Enabled: setAccelerator is not defined for JMenu . |
void |
setComponentOrientation(ComponentOrientation o)
Suppressed: |
void |
setDelay(int d)
Enabled: Sets the suggested delay before the menu's PopupMenu
is popped up or down. |
void |
setMenuLocation(int x,
int y)
Enabled: Sets the location of the popup component. |
void |
setModel(ButtonModel newModel)
Enabled: Sets the data model for the "menu button" -- the label that the user clicks to open or close the menu. |
void |
setPopupMenuVisible(boolean b)
Enabled: Sets the visibility of the menu's popup. |
void |
setSelected(boolean b)
Enabled: Sets the selection status of the menu. |
private Point |
translateToPopupMenu(int x,
int y)
|
private Point |
translateToPopupMenu(Point p)
|
void |
updateUI()
Enabled: Resets the UI property with a value from the current look and feel. |
private void |
writeObject(ObjectOutputStream s)
See readObject and writeObject in
JComponent for more
information about serialization in Swing. |
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 |
private static final String uiClassID
getUIClassID()
,
JMenuItem.readObject(java.io.ObjectInputStream)
private JPopupMenu popupMenu
private ChangeListener menuChangeListener
private MenuEvent menuEvent
private static Hashtable listenerRegistry
private int delay
private Point customMenuLocation
private static final boolean TRACE
private static final boolean VERBOSE
private static final boolean DEBUG
protected javax.swing.JMenu.WinListener popupListener
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 labelpublic 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 |
void initFocusability()
JMenuItem
doesn't want to be, thus we override this
do nothing. We don't invoke setFocusable(true)
after
super's constructor has completed as this has the side effect that
JMenu
will be considered traversable via the
keyboard, which we don't want. Making a Component traversable by
the keyboard after invoking setFocusable(true)
is OK,
as setFocusable
is new API
and is speced as such, but internally we don't want to use it like
this else we change the keyboard traversability.
initFocusability
in class JMenuItem
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 ButtonModel
AbstractButton.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 menupublic boolean isPopupMenuVisible()
public void setPopupMenuVisible(boolean b)
b
- a boolean value -- true to make the menu visible,
false to hide itprotected 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 menupublic 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
propertypublic 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 delayprivate void ensurePopupMenuCreated()
private Point getCustomMenuLocation()
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 added
JMenuItem
addedpublic 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()
,
#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)
,
java.awt.Container#add(Component, int)
public JMenuItem add(String s)
s
- the string for the menu item to be addedpublic 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
Action
s 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 java.beans.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
Action
s 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 itempublic 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
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 itempublic void insertSeparator(int index)
index
- an integer specifying the position at which to
insert the menu separatorpublic 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 itempublic int getItemCount()
getMenuComponentCount()
public boolean isTearOff()
public void remove(JMenuItem item)
item
- the JMenuItem
to be removed from the menupublic void remove(int pos)
remove
in class Container
pos
- the position of the item to be removedContainer.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)
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 menupublic Component[] getMenuComponents()
Component
s of the menu's
subcomponents. Note that this returns all Component
s
in the popup menu, including separators.
Component
s or an empty array
if there is no popup menupublic boolean isTopLevelMenu()
public boolean isMenuComponent(Component c)
c
- the Component
to be tested
Component
exists, false otherwiseprivate Point translateToPopupMenu(Point p)
private Point translateToPopupMenu(int x, int y)
public JPopupMenu getPopupMenu()
public void addMenuListener(MenuListener l)
l
- the listener to be addedpublic void removeMenuListener(MenuListener l)
l
- the listener to be removedpublic MenuListener[] getMenuListeners()
MenuListener
s added
to this JMenu with addMenuListener().
MenuListener
s added or an empty
array if no listeners have been addedprotected void fireMenuSelected()
EventListenerList
protected void fireMenuDeselected()
EventListenerList
protected void fireMenuCanceled()
EventListenerList
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 null
Action
,
AbstractButton.setAction(javax.swing.Action)
private ChangeListener createMenuChangeListener()
protected javax.swing.JMenu.WinListener createWinListener(JPopupMenu p)
p
- the JPopupMenu
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()
MenuElement
s 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
JSeparator
s do not conform to the MenuElement
interface, this array will only contain JMenuItem
s.
getSubElements
in interface MenuElement
getSubElements
in class JMenuItem
MenuElement
objectspublic 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
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
java.awt.Component#setComponentOrientation
,
java.awt.Component#getComponentOrientation
public void setComponentOrientation(ComponentOrientation o)
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 hierarchyprotected void processKeyEvent(KeyEvent evt)
processKeyEvent
in class JComponent
evt
- the key event to be processedjava.awt.event.KeyEvent
,
java.awt.event.KeyListener
,
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 forprivate MenuElement[] buildMenuElementArray(JMenu leaf)
private void writeObject(ObjectOutputStream s) throws IOException
readObject
and writeObject
in
JComponent
for more
information about serialization in Swing.
s
- the ObjectOutputStream
in which to write
IOException
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 |