Here you can find the source of makeButtonsSameSize(JButton[] buttons)
public static void makeButtonsSameSize(JButton[] buttons)
//package com.java2s; //License from project: Open Source License import java.awt.Dimension; import javax.swing.JButton; public class Main { public static void makeButtonsSameSize(JButton[] buttons) { if (buttons.length < 2) { return; // nothing to do }//from ww w . j a va2 s. c o m Dimension size = buttons[0].getPreferredSize(); int maxWidth = size.width; int maxHeight = size.height; int i; for (i = 1; i < buttons.length; i++) { size = buttons[i].getPreferredSize(); if (size.width > maxWidth) { maxWidth = size.width; } if (size.height > maxHeight) { maxHeight = size.height; } } size = new Dimension(maxWidth, maxHeight); for (i = 0; i < buttons.length; i++) { buttons[i].setPreferredSize(size); buttons[i].setMinimumSize(size); buttons[i].setMaximumSize(size); } } }