RelativePoint (@NotNull DataContext dataContext) { Rectangle dominantArea = PlatformDataKeys.DOMINANT_HINT_AREA_RECTANGLE.getData(dataContext); if (dominantArea != null) { final Component focusedComponent = getWndManager().getFocusedComponent(myProject); if (focusedComponent != null) { Window window = SwingUtilities.windowForComponent(focusedComponent); JLayeredPane layeredPane; if (window instanceof JFrame) { layeredPane = ((JFrame)window).getLayeredPane(); } else if (window instanceof JDialog) { layeredPane = ((JDialog)window).getLayeredPane(); } else if (window instanceof JWindow) { layeredPane = ((JWindow)window).getLayeredPane(); } else { throw new IllegalStateException("cannot find parent window: project=" + myProject + "; window=" + window); } return relativePointWithDominantRectangle(layeredPane, dominantArea); } } RelativePoint location; Component contextComponent = dataContext.getData(PlatformCoreDataKeys.CONTEXT_COMPONENT); if (contextComponent == myComponent) { location = new RelativePoint(myComponent, new Point()); } else { location = JBPopupFactory.getInstance().guessBestPopupLocation(dataContext); } if (myLocateWithinScreen) { Point screenPoint = location.getScreenPoint(); Rectangle rectangle = new Rectangle(screenPoint, getSizeForPositioning()); Rectangle screen = ScreenUtil.getScreenRectangle(screenPoint); ScreenUtil.moveToFit(rectangle, screen, null); location = new RelativePoint(rectangle.getLocation()).getPointOn(location.getComponent()); } return location; }