Here you can find the source of evenSizes(JComponent[] components)
public static void evenSizes(JComponent[] components)
//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); } } }