JSpinner spinner = new JSpinner(new SpinnerNumberModel(value, min, max, 1));
spinner.setBounds(x,y,width,height);
// 控制输入
JSpinner.NumberEditor editor = new JSpinner.NumberEditor(spinner, "0");
spinner.setEditor(editor);
JFormattedTextField textField = ((JSpinner.NumberEditor) spinner.getEditor())
.getTextField();
textField.setEditable(true);
DefaultFormatterFactory factory = (DefaultFormatterFactory) textField
.getFormatterFactory();
NumberFormatter formatter = (NumberFormatter) factory.getDefaultFormatter();
formatter.setAllowsInvalid(false);
add(spinner);
原文:http://www.blogjava.net/aoneany/articles/260124.html