Java tutorial
//package com.java2s; /* * Copyright (C) 2009 Klaus Reimer <k@ailis.de> * See LICENSE.md for licensing information. */ import java.awt.Dimension; import javax.swing.JComponent; public class Main { /** * Sets the preferred height of the specified component. * * @param component * The component * @param height * The preferred height */ public static void setPreferredHeight(final JComponent component, final int height) { component.setPreferredSize(new Dimension(component.getPreferredSize().width, height)); } }