Dimension () { int MIN_WIDTH = JBUI.scale(350); int MAX_WIDTH = JBUI.scale(550); Dimension size = super.getPreferredSize(); int width = size.width; int height = size.height; if (width > MAX_WIDTH) { setSize(MAX_WIDTH, height); validate(); size = super.getPreferredSize(); width = size.width; height = size.height; } return new Dimension(Math.max(MIN_WIDTH, Math.min(MAX_WIDTH, width)), Math.min(MAX_WIDTH, height)); }