Dimension (Container parent) { Dimension size1 = myPanel.getPreferredSize(); Dimension size2 = myOptionsPanel.getPreferredSize(); return new Dimension(size1.width + size2.width, max(size1.height, size2.height)); }