Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.Dimension; public class Main { public static void setSizes(Component comp, Dimension dim) { comp.setMinimumSize(dim); comp.setPreferredSize(dim); comp.setMaximumSize(new Dimension(Short.MAX_VALUE, (int) comp.getPreferredSize().getHeight())); } }