Java Utililty Methods JComponent Height

List of utility methods to do JComponent Height

Description

The list of methods to do JComponent Height are organized into topic(s).

Method

voidadjustHeight(JComponent comp, int height)
adjust Height
Dimension size = comp.getMinimumSize();
size.height = height;
comp.setMinimumSize(size);
size = comp.getPreferredSize();
size.height = height;
comp.setPreferredSize(size);
voidfixHeight(JComponent c, int height)
fix Height
Dimension ps = c.getPreferredSize();
c.setPreferredSize(new Dimension(ps.width, height));
c.setMinimumSize(c.getPreferredSize());
c.setMaximumSize(c.getPreferredSize());
intgetComponentHeight(JComponent component)
get Component Height
int height = component.getHeight();
return (height > 0 ? height : component.getPreferredSize().height);
intgetMinimumHeight(JComponent comp)
get Minimum Height
return comp.getMinimumSize().height;
voidheighten(JComponent component, int px)
heighten
pad(component, 0, px);
voidmakeEqualHeight(JComponent reference, JComponent... others)
make Equal Height
if (reference == null)
    return;
if (others == null)
    return;
int height = reference.getPreferredSize().height;
for (JComponent comp : others) {
    Dimension size = comp.getPreferredSize();
    size.height = height;
...
voidnormalizeHeight(JComponent... components)
Sets all specified components to the same height.
int height = 0;
for (JComponent component : components) {
    if (component.getPreferredSize().height > height) {
        height = component.getPreferredSize().height;
setPreferredHeight(height, components);
voidsameHeight(JComponent[] components, int height)
same Height
for (int i = 0; i < components.length; i++) {
    Dimension size = components[i].getSize();
    size.height = height;
    components[i].setSize(size);
voidsetComponentHeight(JComponent setme, JComponent getme)
Set the component height to that of another component.
setComponentHeight(setme, getme, 0);
voidsetMaxHeightToPreferred(JComponent component)
Sets the maximum size of a JComponent to the preferred size
component.setMaximumSize(new Dimension(Integer.MAX_VALUE, component.getPreferredSize().height));