Dimension () { Dimension dim = super.getPreferredSize(); Insets m = getMargin(); var fm = getFontMetrics(getFont()); var text = getText(); var emptyText = getEmptyText().getText(); dim.width = Math.max(fm.stringWidth(text), fm.stringWidth(emptyText)) + 10 + m.left + m.right; return dim; }