Dimension (Container parent) { int totalWidth = 0; int totalHeight = 0; for (JComponent component : Arrays.asList(myTitle, myTopBreadcrumbs, myContent, myBottomBreadcrumbs)) { Dimension size = getPreferredSize(component); totalWidth = Math.max(size.width, totalWidth); totalHeight += size.height; if (component == myTitle && size.height != 0) { totalHeight += DiffUtil.TITLE_GAP.get(); } } return new Dimension(totalWidth, totalHeight); }