void (final Dimension size) { if (myIsRealPopup && myPopup != null && !myPopup.isDisposed()) { // There is a possible case that a popup wraps target content component into other components which might have borders. // That's why we can't just apply component's size to the whole popup. It needs to be adjusted before that. JComponent popupContent = myPopup.getContent(); int widthExpand = 0; int heightExpand = 0; boolean adjustSize = false; JComponent prev = myComponent; for (Container c = myComponent.getParent(); c != null; c = c.getParent()) { if (c == popupContent) { adjustSize = true; break; } if (c instanceof JComponent) { Border border = ((JComponent)c).getBorder(); if (prev != null && border != null) { Insets insets = border.getBorderInsets(prev); widthExpand += insets.left + insets.right; heightExpand += insets.top + insets.bottom; } prev = (JComponent)c; } else { prev = null; } } Dimension sizeToUse = size; if (adjustSize && (widthExpand != 0 || heightExpand != 0)) { sizeToUse = new Dimension(size.width + widthExpand, size.height + heightExpand); } myPopup.setSize(sizeToUse); } else if (!isAwtTooltip()) { myComponent.setSize(size); myComponent.revalidate(); myComponent.repaint(); } else { // isAwtTooltip() case, we have to update Balloon size Component c = myComponent; while (c != null) { if (c.getParent() instanceof JLayeredPane) { c.setSize(c.getPreferredSize()); c.revalidate(); c.repaint(); break; } c = c.getParent(); } } }