< prev index next >

src/java.desktop/share/classes/java/awt/MenuBar.java

Print this page




 205                 }
 206             }
 207         }
 208     }
 209 
 210     /**
 211      * Adds the specified menu to the menu bar.
 212      * If the menu has been part of another menu bar,
 213      * removes it from that menu bar.
 214      *
 215      * @param        m   the menu to be added
 216      * @return       the menu added
 217      * @see          java.awt.MenuBar#remove(int)
 218      * @see          java.awt.MenuBar#remove(java.awt.MenuComponent)
 219      */
 220     public Menu add(Menu m) {
 221         synchronized (getTreeLock()) {
 222             if (m.parent != null) {
 223                 m.parent.remove(m);
 224             }
 225             menus.addElement(m);
 226             m.parent = this;
 227 
 228             MenuBarPeer peer = (MenuBarPeer)this.peer;
 229             if (peer != null) {
 230                 if (m.peer == null) {
 231                     m.addNotify();
 232                 }
 233                 peer.addMenu(m);
 234             }

 235             return m;
 236         }
 237     }
 238 
 239     /**
 240      * Removes the menu located at the specified
 241      * index from this menu bar.
 242      * @param        index   the position of the menu to be removed.
 243      * @see          java.awt.MenuBar#add(java.awt.Menu)
 244      */
 245     public void remove(final int index) {
 246         synchronized (getTreeLock()) {
 247             Menu m = getMenu(index);
 248             menus.removeElementAt(index);
 249             MenuBarPeer peer = (MenuBarPeer)this.peer;
 250             if (peer != null) {

 251                 m.removeNotify();
 252                 m.parent = null;
 253                 peer.delMenu(index);
 254             }
 255             if (helpMenu == m) {
 256                 helpMenu = null;
 257                 m.isHelpMenu = false;
 258             }
 259         }
 260     }
 261 
 262     /**
 263      * Removes the specified menu component from this menu bar.
 264      * @param        m the menu component to be removed.
 265      * @see          java.awt.MenuBar#add(java.awt.Menu)
 266      */
 267     public void remove(MenuComponent m) {
 268         synchronized (getTreeLock()) {
 269             int index = menus.indexOf(m);
 270             if (index >= 0) {
 271                 remove(index);
 272             }
 273         }




 205                 }
 206             }
 207         }
 208     }
 209 
 210     /**
 211      * Adds the specified menu to the menu bar.
 212      * If the menu has been part of another menu bar,
 213      * removes it from that menu bar.
 214      *
 215      * @param        m   the menu to be added
 216      * @return       the menu added
 217      * @see          java.awt.MenuBar#remove(int)
 218      * @see          java.awt.MenuBar#remove(java.awt.MenuComponent)
 219      */
 220     public Menu add(Menu m) {
 221         synchronized (getTreeLock()) {
 222             if (m.parent != null) {
 223                 m.parent.remove(m);
 224             }

 225             m.parent = this;
 226 
 227             MenuBarPeer peer = (MenuBarPeer)this.peer;
 228             if (peer != null) {
 229                 if (m.peer == null) {
 230                     m.addNotify();
 231                 }
 232                 peer.addMenu(m);
 233             }
 234             menus.addElement(m);
 235             return m;
 236         }
 237     }
 238 
 239     /**
 240      * Removes the menu located at the specified
 241      * index from this menu bar.
 242      * @param        index   the position of the menu to be removed.
 243      * @see          java.awt.MenuBar#add(java.awt.Menu)
 244      */
 245     public void remove(final int index) {
 246         synchronized (getTreeLock()) {
 247             Menu m = getMenu(index);
 248             menus.removeElementAt(index);
 249             MenuBarPeer peer = (MenuBarPeer)this.peer;
 250             if (peer != null) {
 251                 peer.delMenu(index);
 252                 m.removeNotify();
 253                 m.parent = null;

 254             }
 255             if (helpMenu == m) {
 256                 helpMenu = null;
 257                 m.isHelpMenu = false;
 258             }
 259         }
 260     }
 261 
 262     /**
 263      * Removes the specified menu component from this menu bar.
 264      * @param        m the menu component to be removed.
 265      * @see          java.awt.MenuBar#add(java.awt.Menu)
 266      */
 267     public void remove(MenuComponent m) {
 268         synchronized (getTreeLock()) {
 269             int index = menus.indexOf(m);
 270             if (index >= 0) {
 271                 remove(index);
 272             }
 273         }


< prev index next >