JSpinner限制输入格式【转】

   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

posted @ 2012-11-02 19:22  Leo Forest  阅读(284)  评论(0编辑  收藏  举报