/** * Returns a point where the given popup menu should be shown. The point is * calculated by adjusting the X and Y coordinates from the given mouse * event so that the popup menu will not be clipped by the screen * boundaries. * * @param popup * the popup menu * @param event * the mouse event * @return the point where the popup menu should be shown */ public static Point getPopupMenuShowPoint(JPopupMenu popup, MouseEvent event) { Component source = (Component) event.getSource(); Point topLeftSource = source.getLocationOnScreen(); Point ptRet = getPopupMenuShowPoint(popup, topLeftSource.x + event.getX(), topLeftSource.y + event.getY()); ptRet.translate(-topLeftSource.x, -topLeftSource.y); return ptRet; }