Dimension (JComponent c) { int vGap = JBUIScale.scale(3); OnOffButton button = (OnOffButton)c; String text = button.getOffText().length() > button.getOnText().length() ? button.getOffText() : button.getOnText(); text = text.toUpperCase(Locale.getDefault()); FontMetrics fm = c.getFontMetrics(c.getFont()); int w = fm.stringWidth(text); int h = fm.getHeight(); h += 2 * vGap; w += 1.25 * h; return new Dimension(w, h); }