Java tutorial
//package com.java2s; import javax.swing.JPanel; import java.awt.Dimension; public class Main { public static JPanel createPanelWithFixedSize(final int preferredWidth) { final JPanel p = new JPanel() { @Override public Dimension getMinimumSize() { return getPreferredSize(); } @Override public Dimension getPreferredSize() { return new Dimension(preferredWidth, super.getPreferredSize().height); } @Override public Dimension getMaximumSize() { return getPreferredSize(); } }; return p; } }