本文整理汇总了Java中java.awt.peer.MenuPeer.addItem方法的典型用法代码示例。如果您正苦于以下问题:Java MenuPeer.addItem方法的具体用法?Java MenuPeer.addItem怎么用?Java MenuPeer.addItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.peer.MenuPeer
的用法示例。
在下文中一共展示了MenuPeer.addItem方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: add
import java.awt.peer.MenuPeer; //导入方法依赖的package包/类
/**
* Adds the specified menu item to this menu. If the
* menu item has been part of another menu, removes it
* from that menu.
*
* @param mi the menu item to be added
* @return the menu item added
* @see java.awt.Menu#insert(java.lang.String, int)
* @see java.awt.Menu#insert(java.awt.MenuItem, int)
*/
public MenuItem add(MenuItem mi) {
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;
}
}
示例2: add
import java.awt.peer.MenuPeer; //导入方法依赖的package包/类
/**
* Adds the specified item to this menu. If it was previously part of
* another menu, it is first removed from that menu.
*
* @param item The new item to add.
*
* @return The item that was added.
*/
public MenuItem add(MenuItem item)
{
MenuContainer parent = item.getParent();
if (parent != null)
parent.remove(item);
items.addElement(item);
item.setParent(this);
if (peer != null)
{
item.addNotify();
MenuPeer mp = (MenuPeer) peer;
mp.addItem(item);
}
return item;
}
示例3: addNotify
import java.awt.peer.MenuPeer; //导入方法依赖的package包/类
/**
* Creates the native peer for this object.
*/
public void addNotify()
{
MenuPeer peer = (MenuPeer) getPeer();
if (peer == null)
{
peer = getToolkit().createMenu(this);
setPeer(peer);
}
Enumeration e = items.elements();
while (e.hasMoreElements())
{
MenuItem mi = (MenuItem)e.nextElement();
mi.addNotify();
peer.addItem(mi);
}
super.addNotify();
}
示例4: add
import java.awt.peer.MenuPeer; //导入方法依赖的package包/类
/**
* Adds the specified menu item to this menu. If the
* menu item has been part of another menu, removes it
* from that menu.
*
* @param mi the menu item to be added
* @return the menu item added
* @see java.awt.Menu#insert(java.lang.String, int)
* @see java.awt.Menu#insert(java.awt.MenuItem, int)
*/
public MenuItem add(MenuItem mi) {
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;
}
}
示例5: insert
import java.awt.peer.MenuPeer; //导入方法依赖的package包/类
/**
* Inserts the specified menu item into this menu at the specified index. If
* the index is greater than or equal to the number of items already in the
* menu, the new item is added as the last item in the menu.
*
* @param item The menu item to add (<code>null</code> not permitted).
* @param index The index of the menu item (>= 0).
*
* @throws IllegalArgumentException if the index is less than zero.
* @throws NullPointerException if <code>item</code> is <code>null</code>.
*/
public void insert(MenuItem item, int index)
{
if (index < 0)
throw new IllegalArgumentException("Index is less than zero");
int count = getItemCount();
if (index >= count)
add(item);
else
{
MenuContainer parent = item.getParent();
if (parent != null)
parent.remove(item);
items.insertElementAt(item, index);
item.setParent(this);
MenuPeer peer = (MenuPeer) getPeer();
if (peer == null)
return;
for (int i = count - 1; i >= index; i--)
peer.delItem(i);
item.addNotify();
peer.addItem(item);
// bear in mind that count is the number of items *before* the new
// item was added
for (int i = index + 1; i <= count; i++)
peer.addItem((MenuItem) items.elementAt(i));
}
}
示例6: insert
import java.awt.peer.MenuPeer; //导入方法依赖的package包/类
/**
* Inserts the specified menu item into this menu at the specified index. If
* the index is greater than or equal to the number of items already in the
* menu, the new item is added as the last item in the menu.
*
* @param item The menu item to add (<code>null</code> not permitted).
* @param index The index of the menu item (>= 0).
*
* @throws IllegalArgumentException if the index is less than zero.
* @throws NullPointerException if <code>item</code> is <code>null</code>.
*/
public void insert(MenuItem item, int index)
{
if (index < 0)
throw new IllegalArgumentException("Index is less than zero");
int count = getItemCount();
if (index >= count)
add(item);
else
{
MenuContainer parent = item.getParent();
if (parent != null)
parent.remove(item);
items.insertElementAt(item, index);
item.setParent(this);
MenuPeer peer = (MenuPeer) getPeer();
if (peer == null)
return;
for (int i = count - 1; i >= index; i--)
peer.delItem(i);
item.addNotify();
peer.addItem(item);
// bear in mind that count is the number of items *before* the new
// item was added
for (int i = index + 1; i <= count; i++)
peer.addItem((MenuItem) items.elementAt(i));
}
}