Here you can find the source of setSize(JComponent c, int w)
private static void setSize(JComponent c, int w)
//package com.java2s; //License from project: Apache License import java.awt.Dimension; import javax.swing.JComponent; public class Main { private static void setSize(JComponent c, int w) { Dimension d = new Dimension(w, c.getPreferredSize().height); c.setMinimumSize(d);/* www . j a v a 2 s. c o m*/ c.setPreferredSize(d); c.setMaximumSize(d); } }