Dimension (Container parent) { int width = parent.getWidth(); int height = 0; for (Component component : parent.getComponents()) { if (component instanceof PaletteGroupComponent groupComponent) { height += groupComponent.getHeight(); if (groupComponent.isSelected()) { height += groupComponent.getItemsComponent().getPreferredHeight(width); } } } return new Dimension(10, height); }