Dimension (final JComponent parent) { GridBagLayout gridBag = (GridBagLayout)parent.getLayout(); gridBag.layoutContainer(parent); int[][] layoutDimensions = gridBag.getLayoutDimensions(); int rowCount = layoutDimensions[1].length; int colCount = layoutDimensions[0].length; // account for invisible components for (Component component : parent.getComponents()) { final GridBagConstraints constraints = gridBag.getConstraints(component); colCount = Math.max(colCount, constraints.gridx + constraints.gridwidth); rowCount = Math.max(rowCount, constraints.gridy + constraints.gridheight); } return new Dimension(colCount, rowCount); }