Dimension (Container parent) { int height = 0; int width = parent.getWidth(); for(Component c: parent.getComponents()) { if (c instanceof PaletteGroupHeader groupHeader) { height += groupHeader.getHeight(); if (groupHeader.isSelected()) { height += groupHeader.getComponentList().getPreferredHeight(width); } } } return new Dimension(10 /* not used - tracks viewports width*/, height); }