Java tutorial
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import javax.swing.JComponent; public class Main { public static void setComponent3Width(JComponent c, int width) { Dimension d = new Dimension(width, c.getPreferredSize().height); set3Dimensions(c, d); } public static void set3Dimensions(JComponent c, Dimension d) { c.setMinimumSize(d); c.setPreferredSize(d); c.setMaximumSize(d); } }