JFormattedTextField (@NonNls final String fieldName) { final NumberFormat formatter = NumberFormat.getIntegerInstance(); formatter.setParseIntegerOnly(true); final JFormattedTextField valueField = new JFormattedTextField(formatter); final Object value = ReflectionUtil.getField(getClass(), this, null, fieldName); valueField.setValue(value); valueField.setColumns(4); // hack to work around text field becoming unusably small sometimes when using GridBagLayout valueField.setMinimumSize(valueField.getPreferredSize()); UIUtil.fixFormattedField(valueField); final Document document = valueField.getDocument(); document.addDocumentListener(new DocumentAdapter() { @Override public void textChanged(@NotNull DocumentEvent evt) { try { valueField.commitEdit(); final Number number = (Number)valueField.getValue(); ReflectionUtil.setField(BaseInspection.this.getClass(), BaseInspection.this, int.class, fieldName, number.intValue()); } catch (ParseException e) { // No luck this time. Will update the field when correct value is entered. } } }); return valueField; }