Here you can find the source of resizeToolBarButtons(JComponent toolbar)
static public void resizeToolBarButtons(JComponent toolbar)
//package com.java2s; import java.awt.Component; import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JComponent; public class Main { /** Make the size of all toolbar buttons uniform. *//*from w ww . j av a 2 s .com*/ static public void resizeToolBarButtons(JComponent toolbar) { Component[] components = toolbar.getComponents(); int len = components.length; // Get the maximum dimension Dimension max_dim = new Dimension(0, 0); for (int i = 0; i < len; i++) { if (!(components[i] instanceof JButton)) continue; Dimension size = components[i].getPreferredSize(); if (size.width > max_dim.width) max_dim.width = size.width; if (size.height > max_dim.height) max_dim.height = size.height; } for (int i = 0; i < len; i++) { if (!(components[i] instanceof JButton)) continue; JComponent jcomponent = (JComponent) components[i]; jcomponent.setPreferredSize(max_dim); jcomponent.setMinimumSize(max_dim); jcomponent.setMaximumSize(max_dim); jcomponent.setSize(max_dim); } } }