Methods Summary |
---|
public java.awt.MenuItem | add(java.awt.MenuItem mi)Adds the specified menu item to this menu. If the
menu item has been part of another menu, removes it
from that menu.
synchronized (getTreeLock()) {
if (mi.parent != null) {
mi.parent.remove(mi);
}
items.addElement(mi);
mi.parent = this;
MenuPeer peer = (MenuPeer)this.peer;
if (peer != null) {
mi.addNotify();
peer.addItem(mi);
}
return mi;
}
|
public void | add(java.lang.String label)Adds an item with the specified label to this menu.
add(new MenuItem(label));
|
public void | addNotify()Creates the menu's peer. The peer allows us to modify the
appearance of the menu without changing its functionality.
synchronized (getTreeLock()) {
if (peer == null)
peer = Toolkit.getDefaultToolkit().createMenu(this);
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
MenuItem mi = getItem(i);
mi.parent = this;
mi.addNotify();
}
}
|
public void | addSeparator()Adds a separator line, or a hypen, to the menu at the current position.
add("-");
|
java.lang.String | constructComponentName()Construct a name for this MenuComponent. Called by getName() when
the name is null.
synchronized (getClass()) {
return base + nameCounter++;
}
|
public int | countItems()
return countItemsImpl();
|
final int | countItemsImpl()
return items.size();
|
void | deleteShortcut(java.awt.MenuShortcut s)
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
getItem(i).deleteShortcut(s);
}
|
int | getAccessibleChildIndex(java.awt.MenuComponent child)Defined in MenuComponent. Overridden here.
return items.indexOf(child);
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext associated with this Menu.
For menus, the AccessibleContext takes the form of an
AccessibleAWTMenu.
A new AccessibleAWTMenu instance is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTMenu();
}
return accessibleContext;
|
public java.awt.MenuItem | getItem(int index)Gets the item located at the specified index of this menu.
return getItemImpl(index);
|
public int | getItemCount()Get the number of items in this menu.
return countItems();
|
final java.awt.MenuItem | getItemImpl(int index)
return (MenuItem)items.elementAt(index);
|
java.awt.MenuItem | getShortcutMenuItem(java.awt.MenuShortcut s)
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
MenuItem mi = getItem(i).getShortcutMenuItem(s);
if (mi != null) {
return mi;
}
}
return null;
|
boolean | handleShortcut(java.awt.event.KeyEvent e)
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
MenuItem mi = getItem(i);
if (mi.handleShortcut(e)) {
return true;
}
}
return false;
|
private static native void | initIDs()Initialize JNI field and method IDs
|
public void | insert(java.awt.MenuItem menuitem, int index)Inserts a menu item into this menu
at the specified position.
synchronized (getTreeLock()) {
if (index < 0) {
throw new IllegalArgumentException("index less than zero.");
}
int nitems = getItemCount();
Vector tempItems = new Vector();
/* Remove the item at index, nitems-index times
storing them in a temporary vector in the
order they appear on the menu.
*/
for (int i = index ; i < nitems; i++) {
tempItems.addElement(getItem(index));
remove(index);
}
add(menuitem);
/* Add the removed items back to the menu, they are
already in the correct order in the temp vector.
*/
for (int i = 0; i < tempItems.size() ; i++) {
add((MenuItem)tempItems.elementAt(i));
}
}
|
public void | insert(java.lang.String label, int index)Inserts a menu item with the specified label into this menu
at the specified position. This is a convenience method for
insert(menuItem, index) .
insert(new MenuItem(label), index);
|
public void | insertSeparator(int index)Inserts a separator at the specified position.
synchronized (getTreeLock()) {
if (index < 0) {
throw new IllegalArgumentException("index less than zero.");
}
int nitems = getItemCount();
Vector tempItems = new Vector();
/* Remove the item at index, nitems-index times
storing them in a temporary vector in the
order they appear on the menu.
*/
for (int i = index ; i < nitems; i++) {
tempItems.addElement(getItem(index));
remove(index);
}
addSeparator();
/* Add the removed items back to the menu, they are
already in the correct order in the temp vector.
*/
for (int i = 0; i < tempItems.size() ; i++) {
add((MenuItem)tempItems.elementAt(i));
}
}
|
public boolean | isTearOff()Indicates whether this menu is a tear-off menu.
Tear-off functionality may not be supported by all
implementations of AWT. If a particular implementation doesn't
support tear-off menus, this value is silently ignored.
return tearOff;
|
public java.lang.String | paramString()Returns a string representing the state of this Menu .
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 .
String str = ",tearOff=" + tearOff+",isHelpMenu=" + isHelpMenu;
return super.paramString() + str;
|
private void | readObject(java.io.ObjectInputStream s)Reads the ObjectInputStream .
Unrecognized keys or values will be ignored.
// HeadlessException will be thrown from MenuComponent's readObject
s.defaultReadObject();
for(int i = 0; i < items.size(); i++) {
MenuItem item = (MenuItem)items.elementAt(i);
item.parent = this;
}
|
public void | remove(int index)Removes the menu item at the specified index from this menu.
synchronized (getTreeLock()) {
MenuItem mi = getItem(index);
items.removeElementAt(index);
MenuPeer peer = (MenuPeer)this.peer;
if (peer != null) {
mi.removeNotify();
mi.parent = null;
peer.delItem(index);
}
}
|
public void | remove(java.awt.MenuComponent item)Removes the specified menu item from this menu.
synchronized (getTreeLock()) {
int index = items.indexOf(item);
if (index >= 0) {
remove(index);
}
}
|
public void | removeAll()Removes all items from this menu.
synchronized (getTreeLock()) {
int nitems = getItemCount();
for (int i = nitems-1 ; i >= 0 ; i--) {
remove(i);
}
}
|
public void | removeNotify()Removes the menu's peer. The peer allows us to modify the appearance
of the menu without changing its functionality.
synchronized (getTreeLock()) {
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
getItem(i).removeNotify();
}
super.removeNotify();
}
|
synchronized java.util.Enumeration | shortcuts()
Vector shortcuts = new Vector();
int nitems = getItemCount();
for (int i = 0 ; i < nitems ; i++) {
MenuItem mi = getItem(i);
if (mi instanceof Menu) {
Enumeration e = ((Menu)mi).shortcuts();
while (e.hasMoreElements()) {
shortcuts.addElement(e.nextElement());
}
} else {
MenuShortcut ms = mi.getShortcut();
if (ms != null) {
shortcuts.addElement(ms);
}
}
}
return shortcuts.elements();
|
private void | writeObject(java.io.ObjectOutputStream s)Writes default serializable fields to stream.
s.defaultWriteObject();
|