Dimension (Container target) { Dimension dimension = super.preferredLayoutSize(target); int maxHeight = getMaxHeight(); switchTimer(dimension.height > maxHeight); dimension.height = Math.min(maxHeight, dimension.height); return dimension; }