Code example for DefaultFormatterFactory

0
            } 
 
            SpinnerMathNumberModel model = (SpinnerMathNumberModel)spinner.getModel();
            NumberFormatter formatter = new MathNumberEditorFormatter(model,
                                                                  format);
            DefaultFormatterFactory factory = new DefaultFormatterFactory(
                                                  formatter);
            JFormattedTextField ftf = getTextField();
            ftf.setEditable(true);
            ftf.setFormatterFactory(factory);
            ftf.setHorizontalAlignment(JTextField.RIGHT);
 
            /* TBD - initializing the column width of the text field 
             * is imprecise and doing it here is tricky because 
             * the developer may configure the formatter later. 
             */ 
            try { 
                String maxString = formatter.valueToString(model.getMinimum());
                String minString = formatter.valueToString(model.getMaximum());
                ftf.setColumns(Math.max(maxString.length(),
Experience pair programming with AI  Get Codota for Java