void (@NotNull JComponent parentComponent, @NotNull Point point, @NotNull JLayeredPane layeredPane) { beforeShow(); final Dimension preferredSize = myComponent.getPreferredSize(); final Point layeredPanePoint = SwingUtilities.convertPoint(parentComponent, point, layeredPane); Rectangle popupRect = new Rectangle(layeredPanePoint.x, layeredPanePoint.y, preferredSize.width, preferredSize.height); int borderGap = JBUI.scale(3); // leave some pretty gap to the edge of frame if (popupRect.getMaxX() > layeredPane.getWidth()) { popupRect.width = layeredPane.getWidth() - popupRect.x - borderGap; } if (popupRect.getMaxY() > layeredPane.getHeight()) { popupRect.height = layeredPane.getHeight() - popupRect.y - borderGap; } myComponent.setBounds(popupRect); layeredPane.add(myComponent, JLayeredPane.POPUP_LAYER); myComponent.validate(); myComponent.repaint(); }