Java tutorial
//package com.java2s; import java.awt.Component; import java.awt.Dimension; public class Main { /** Sets maximum width of the component, leaving the height intact. */ public static void setMaximumWidth(Component component, int width) { Dimension dim = component.getMaximumSize(); component.setMaximumSize(new Dimension(width, dim.height)); } }