Java examples for Swing:JComponent
Sets the maximum size of a JComponent to the preferred size
//package com.java2s; import java.awt.Dimension; import javax.swing.JComponent; public class Main { /**// w w w . j a v a2 s. c om * Sets the maximum size of a {@link JComponent} to the preferred size * * @param component * The component to set the size of */ public static void setMaxHeightToPreferred(JComponent component) { component.setMaximumSize(new Dimension(Integer.MAX_VALUE, component .getPreferredSize().height)); } }