point.y = screenLoc.y - screenBounds.y + size.height - yOffset - popupSize.height;
point.y = size.height - yOffset - popupSize.height;
  protected Point getPopupMenuOrigin()  {    // The menu's screen location and size.    Point screenLoc = getLocationOnScreen();    Dimension size = getSize();    // Determine the popup's size.    JPopupMenu popup = getPopupMenu();    Dimension popupSize = popup.getSize();    if (popupSize.width == 0 || popupSize.height == 0)      popupSize = popup.getPreferredSize();    // Determine screen bounds.    Toolkit tk = Toolkit.getDefaultToolkit();    Rectangle screenBounds = new Rectangle(tk.getScreenSize());    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();    GraphicsDevice gd = ge.getDefaultScreenDevice();    GraphicsConfiguration gc = gd.getDefaultConfiguration();    Insets screenInsets = tk.getScreenInsets(gc);    screenBounds.x -= screenInsets.left;    screenBounds.width -= screenInsets.left + screenInsets.right;    screenBounds.y -= screenInsets.top;    screenBounds.height -= screenInsets.top + screenInsets.bottom;    screenLoc.x -= screenInsets.left;    screenLoc.y -= screenInsets.top;    Point point = new Point();    if (isTopLevelMenu())      {        // If menu in the menu bar.        int xOffset = UIManager.getInt("Menu.menuPopupOffsetX");        int yOffset = UIManager.getInt("Menu.menuPopupOffsetY");        // Determine X location.        if (getComponentOrientation().isLeftToRight())          {            // Prefer popup to the right.            point.x = xOffset;            // Check if it fits, otherwise place popup wherever it fits.            if (screenLoc.x + point.x + popupSize.width                > screenBounds.width + screenBounds.width                && screenBounds.width - size.width                   < 2 * (screenLoc.x - screenBounds.x))              // Popup to the right if there's not enough room.              point.x = size.width - xOffset - popupSize.width;  }        else          {            // Prefer popup to the left.            point.x = size.width - xOffset - popupSize.width;            if (screenLoc.x + point.x < screenBounds.x                && screenBounds.width - size.width                   > 2 * (screenLoc.x - screenBounds.x))              // Popup to the left if there's not enough room.              point.x = xOffset;          }        // Determine Y location. Prefer popping down.        point.y = size.height + yOffset;        if (screenLoc.y + point.y + popupSize.height >= screenBounds.height            && screenBounds.height - size.height               < 2 * (screenLoc.y - screenBounds.y))          // Position above if there's not enough room below.          point.y = - yOffset - popupSize.height;      }    else      {        // If submenu.        int xOffset = UIManager.getInt("Menu.submenuPopupOffsetX");        int yOffset = UIManager.getInt("Menu.submenuPopupOffsetY");        // Determine X location.        if (getComponentOrientation().isLeftToRight())          {            // Prefer popup to the right.            point.x = size.width + xOffset;            if (screenLoc.x + point.x + popupSize.width                >= screenBounds.x + screenBounds.width                && screenBounds.width - size.width                   < 2 * (screenLoc.x - screenBounds.x))              // Position to the left if there's not enough room on the right.              point.x = - xOffset - popupSize.width;          }        else          {            // Prefer popup on the left side.            point.x = - xOffset - popupSize.width;            if (screenLoc.x + point.x < screenBounds.x                && screenBounds.width - size.width                > 2 * (screenLoc.x - screenBounds.x))              // Popup to the right if there's not enough room.              point.x = size.width + xOffset;          }        // Determine Y location. Prefer popping down.        point.y = yOffset;        if (screenLoc.y + point.y + popupSize.height            >= screenBounds.y + screenBounds.height            && screenBounds.height - size.height            < 2 * (screenLoc.y - screenBounds.y))        {          // Pop up if there's not enough room below.// @classpath-bugfix 6/9/2006 Martin Husted Hartvig (hagar@jnode.org) :          point.y = screenLoc.y - screenBounds.y + size.height - yOffset - popupSize.height;// @classpath-bugfix-end        }      }    return point;  }