Java tutorial
//package com.java2s; import java.awt.Dimension; import javax.swing.JComponent; public class Main { /** * Fixes the height of the component but maintaining it old width. * * @param comp * @param height */ public static void fixHeight(JComponent comp, int height) { comp.setPreferredSize(new Dimension(comp.getPreferredSize().width, height)); } }