Dimension (Container parent) { int prefWidth = 0; int prefHeight = 0; for (Component each : myComponents) { Dimension min = each.getPreferredSize(); prefWidth = Math.max(prefWidth, min.width); prefHeight = Math.max(prefHeight, min.height); } return new Dimension(prefWidth, prefHeight); }