Java JComponent Size evenSizes(JComponent[] components)

Here you can find the source of evenSizes(JComponent[] components)

Description

Makes all sizes (min, pref, max) the same to the respective maximum of all given components.

License

LGPL

Declaration

public static void evenSizes(JComponent[] components) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.awt.*;
import javax.swing.*;

public class Main {
    /**//from  w  w w . ja  v a  2s .c  om
     * Makes all sizes (min, pref, max) the same to the respective maximum of
     * all given components.
     * Helpfull if you want to have several components (eg buttons) of the same
     * size regardless of their content.
     */
    public static void evenSizes(JComponent[] components) {
        Dimension minSize = new Dimension(Integer.MIN_VALUE,
                Integer.MIN_VALUE);
        Dimension prefSize = new Dimension(Integer.MIN_VALUE,
                Integer.MIN_VALUE);
        Dimension maxSize = new Dimension(Integer.MIN_VALUE,
                Integer.MIN_VALUE);

        for (int i = 0; i < components.length; i++) {
            Dimension min = components[i].getMinimumSize();
            if (min.width > minSize.width)
                minSize.width = min.width;
            if (min.height > minSize.height)
                minSize.height = min.height;

            Dimension pref = components[i].getPreferredSize();
            if (pref.width > prefSize.width)
                prefSize.width = pref.width;
            if (pref.height > prefSize.height)
                prefSize.height = pref.height;

            Dimension max = components[i].getMaximumSize();
            if (max.width > maxSize.width)
                maxSize.width = max.width;
            if (max.height > maxSize.height)
                maxSize.height = max.height;
        }

        for (int i = 0; i < components.length; i++) {
            components[i].setMinimumSize(minSize);
            components[i].setPreferredSize(prefSize);
            components[i].setMaximumSize(maxSize);
        }
    }
}

Related

  1. doSetSize(final Component component, final int width, final int height)
  2. doSetSizeInEDT(final Component component, final int width, final int height)
  3. emphasizeToolTip()
  4. equalizeSize(final JComponent... components)
  5. equalizeSizes(JComponent[] components)
  6. findCenterBounds(Dimension componentSize)
  7. fixSize(JComponent c, Dimension d)
  8. fixSize(JComponent... items)
  9. fixSize(T comp, int width)