Java examples for Swing:JComponent
Freezes the size of the given component, preventing it from expanding to fill any additional space.
//package com.java2s; import java.awt.Dimension; import javax.swing.JComponent; public class Main { /**//from ww w. j ava 2 s .c o m * Freezes the size of the given component, preventing it from expanding * to fill any additional space. * @param component the component to freeze * @return the component passed in, for chaining purposes */ public static JComponent freezeSize(JComponent component) { return freezeSize(component, component.getPreferredSize().width, component.getPreferredSize().height); } /** * Freezes the size of the given component to the given size, preventing * it from expanding to fill any additional space. * @param component the component to freeze * @param width the width to freeze the component to * @param height the height to freeze the component to * @return the component passed in, for chaining purposes */ public static JComponent freezeSize(JComponent component, int width, int height) { component.setMinimumSize(new Dimension(width, height)); component.setPreferredSize(new Dimension(width, height)); component.setMaximumSize(new Dimension(width, height)); return component; } }