Point screenLoc = getLocationOnScreen(); Dimension size = getSize();   JPopupMenu popup = getPopupMenu(); Dimension popupSize = popup.getSize(); if (popupSize.width == 0 || popupSize.height == 0) popupSize = popup.getPreferredSize();   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();
  protected Point getPopupMenuOrigin()  {    // if menu in the menu bar    if (isTopLevelMenu())      return new Point(0, this.getHeight());    // if submenu                return new Point(this.getWidth(), 0);  }