Here you can find the source of makeSameSize(Component... components)
public static void makeSameSize(Component... components)
//package com.java2s; //License from project: LGPL import javax.swing.*; import java.awt.*; public class Main { public static void makeSameSize(Component... components) { makeSameHeight(components);/*from w ww .j a v a 2 s . c o m*/ makeSameWidth(components); } public static void makeSameSize(int alignment, JLabel... labels) { makeSameSize(labels); for (JLabel label : labels) { label.setHorizontalAlignment(alignment); } } public static void makeSameHeight(Component... components) { int maxHeight = 0; for (Component component : components) { if (component.getPreferredSize().height > maxHeight) { maxHeight = component.getPreferredSize().height; } } for (Component component : components) { final Dimension size = component.getPreferredSize(); size.setSize(size.width, maxHeight); component.setMinimumSize(size); component.setPreferredSize(size); component.setMaximumSize(size); } } public static void makeSameWidth(Component... components) { int maxWidth = 0; for (Component component : components) { if (component.getPreferredSize().width > maxWidth) { maxWidth = component.getPreferredSize().width; } } for (Component component : components) { final Dimension size = component.getPreferredSize(); size.setSize(maxWidth, size.height); component.setMinimumSize(size); component.setPreferredSize(size); component.setMaximumSize(size); } } }