AbstractAction (@NotNull JSpinner spinner, @NotNull JFormattedTextField field, int inc) { return new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { int newValue = getIntValue(spinner) + inc; SpinnerNumberModel model = (SpinnerNumberModel)spinner.getModel(); if (newValue <= (Integer)model.getMaximum() && newValue >= (Integer)model.getMinimum()) { boolean hasSelection = field.getSelectionStart() != field.getSelectionEnd(); model.setValue(newValue); if (hasSelection) field.selectAll(); } } }; }