Dimension () { final Dimension preferredSize = super.getPreferredSize(); final Container parent = getParent(); if (parent != null) { return new Dimension(preferredSize.width, Math.min(150, preferredSize.height)); } return preferredSize; }