Java tutorial
//package com.java2s; import java.awt.Dimension; import javax.swing.JComponent; public class Main { public static void sizeIt(JComponent c, int width, int height) { if (height < 0) { height = c.getPreferredSize().height; } Dimension myDimension = new Dimension(width, height); c.setMaximumSize(myDimension); c.setMinimumSize(myDimension); c.setPreferredSize(myDimension); } }