Dimension (Object component, int dx, int dy, String defaultalignment) { String text = getString(component, "text", null); int tw = 0; int th = 0; if (text != null) { FontMetrics fm = getFontMetrics(getFont()); tw = fm.stringWidth(text); th = fm.getAscent() + fm.getDescent(); } Image icon = getIcon(component, "icon", null); int iw = 0; int ih = 0; if (icon != null) { iw = icon.getWidth(this); ih = icon.getHeight(this); } return new Dimension(tw + iw + dx, Math.max(th, ih) + dy); }