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

Print this page




 104     String constructComponentName() {
 105         synchronized (PopupMenu.class) {
 106             return base + nameCounter++;
 107         }
 108     }
 109 
 110     /**
 111      * Creates the popup menu's peer.
 112      * The peer allows us to change the appearance of the popup menu without
 113      * changing any of the popup menu's functionality.
 114      */
 115     public void addNotify() {
 116         synchronized (getTreeLock()) {
 117             // If our parent is not a Component, then this PopupMenu is
 118             // really just a plain, old Menu.
 119             if (parent != null && !(parent instanceof Component)) {
 120                 super.addNotify();
 121             }
 122             else {
 123                 if (peer == null)
 124                     peer = Toolkit.getDefaultToolkit().createPopupMenu(this);
 125                 int nitems = getItemCount();
 126                 for (int i = 0 ; i < nitems ; i++) {
 127                     MenuItem mi = getItem(i);
 128                     mi.parent = this;
 129                     mi.addNotify();
 130                 }
 131             }
 132         }
 133     }
 134 
 135    /**
 136      * Shows the popup menu at the x, y position relative to an origin
 137      * component.
 138      * The origin component must be contained within the component
 139      * hierarchy of the popup menu's parent.  Both the origin and the parent
 140      * must be showing on the screen for this method to be valid.
 141      * <p>
 142      * If this <code>PopupMenu</code> is being used as a <code>Menu</code>
 143      * (i.e., it has a non-<code>Component</code> parent),
 144      * then you cannot call this method on the <code>PopupMenu</code>.




 104     String constructComponentName() {
 105         synchronized (PopupMenu.class) {
 106             return base + nameCounter++;
 107         }
 108     }
 109 
 110     /**
 111      * Creates the popup menu's peer.
 112      * The peer allows us to change the appearance of the popup menu without
 113      * changing any of the popup menu's functionality.
 114      */
 115     public void addNotify() {
 116         synchronized (getTreeLock()) {
 117             // If our parent is not a Component, then this PopupMenu is
 118             // really just a plain, old Menu.
 119             if (parent != null && !(parent instanceof Component)) {
 120                 super.addNotify();
 121             }
 122             else {
 123                 if (peer == null)
 124                     peer = getComponentFactory().createPopupMenu(this);
 125                 int nitems = getItemCount();
 126                 for (int i = 0 ; i < nitems ; i++) {
 127                     MenuItem mi = getItem(i);
 128                     mi.parent = this;
 129                     mi.addNotify();
 130                 }
 131             }
 132         }
 133     }
 134 
 135    /**
 136      * Shows the popup menu at the x, y position relative to an origin
 137      * component.
 138      * The origin component must be contained within the component
 139      * hierarchy of the popup menu's parent.  Both the origin and the parent
 140      * must be showing on the screen for this method to be valid.
 141      * <p>
 142      * If this <code>PopupMenu</code> is being used as a <code>Menu</code>
 143      * (i.e., it has a non-<code>Component</code> parent),
 144      * then you cannot call this method on the <code>PopupMenu</code>.