void (final Tree tree, JComponent toolbar, JBPopup popup, boolean canShrink) { final Window popupWindow = SwingUtilities.windowForComponent(popup.getContent()); if (popupWindow == null) return; final Dimension size = tree.getPreferredSize(); int hMargin = JBUI.scale(30); int vMargin = JBUI.scale(30); int width = Math.max(size.width, toolbar.getPreferredSize().width) + hMargin; Rectangle bounds = tree.getRowBounds(tree.getRowCount() - 1); int height = toolbar.getHeight() + vMargin + (bounds == null ? 0 : bounds.y + bounds.height); Rectangle screenRectangle = ScreenUtil.getScreenRectangle(toolbar); int maxWidth = screenRectangle.width / 2; int maxHeight = screenRectangle.height / 2; int newWidth = Math.min(width, maxWidth); int newHeight = Math.min(height, maxHeight); if (!canShrink) { newWidth = Math.max(newWidth, popupWindow.getWidth()); newHeight = Math.max(newHeight, popupWindow.getHeight()); } updatePopupBounds(popupWindow, newWidth, newHeight); }