Here you can find the source of setMaximumWidth(final JComponent component, final int width)
static void setMaximumWidth(final JComponent component, final int width)
//package com.java2s; //License from project: Apache License import java.awt.Dimension; import javax.swing.JComponent; public class Main { static void setMaximumWidth(final JComponent component, final int width) { final Dimension preferredSize = component.getPreferredSize(); final Dimension size = new Dimension(width, preferredSize.height); component.setMaximumSize(size);//from ww w.j a va 2 s . co m } }