Here you can find the source of maxSize(Component component, String maxString)
public static Dimension maxSize(Component component, String maxString)
//package com.java2s; //License from project: Apache License import java.awt.*; public class Main { public static Dimension maxSize(Component component, String maxString) { FontMetrics fontMetrics = component.getFontMetrics(component.getFont()); return new Dimension(Math.max(fontMetrics.stringWidth(maxString), component.getPreferredSize().width), fontMetrics.getHeight()); }/*from www. j a va 2s .c o m*/ }