Dimension (Container parent) { int count = parent.getComponentCount(); int width = 0; int height = 0; for (int i = 0; i < count; i++) { Dimension size = parent.getComponent(i).getPreferredSize(); width = Math.max(width, size.width); height += size.height; } height += VERTICAL_GAP * (count - 1); return new Dimension(Math.max(width + JBUIScale.scale(32), BalloonLayoutConfiguration.MaxWidth()), height); }