void (final int charCount) { super.setTextFieldPreferredWidth(charCount); final Component comp = getChildComponent().getEditor().getEditorComponent(); Dimension size = comp.getPreferredSize(); FontMetrics fontMetrics = comp.getFontMetrics(comp.getFont()); size.width = fontMetrics.charWidth('a') * charCount; comp.setPreferredSize(size); }