Dimension () { int width = myMinimumAndPreferredWidth; Dimension preferredSize = super.getPreferredSize(); if (width < 0) { width = preferredSize.width; } return new Dimension(width, preferredSize.height); }