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