Dimension (Container container, Dimension size) { Insets insets = container.getInsets(); if (insets != null) { int width = size.width + insets.left + insets.right; if (size.width < width) size.width = width; int height = size.height + insets.top + insets.bottom; if (size.height < height) size.height = height; } return size; }