Here you can find the source of findMaxLabelWidth(JLabel... jLabels)
public static int findMaxLabelWidth(JLabel... jLabels)
//package com.java2s; //License from project: Apache License import java.awt.FontMetrics; import javax.swing.JLabel; public class Main { public static int findMaxLabelWidth(JLabel... jLabels) { int maxvalue = 0; for (JLabel label : jLabels) { FontMetrics fm = label.getFontMetrics(label.getFont()); int width = fm.stringWidth(label.getText()); if (maxvalue < width) { maxvalue = width;// w ww . ja v a2 s .c o m } } return maxvalue; } }