Container (final Component child, final GridConstraints c) { if (c.isUseParentLayout() && child instanceof Container) { Container container = (Container) child; if (container.getLayout() instanceof GridLayoutManager) { return container; } else if (container.getComponentCount() == 1 && container.getComponent(0) instanceof Container) { // "use parent layout" also needs to work in cases where a grid is the only control in a non-grid panel // which is contained in a grid Container childContainer = (Container) container.getComponent(0); if (childContainer.getLayout() instanceof GridLayoutManager) { return childContainer; } } } return null; }