title: JFormattedTextField to format percent numbers?
body: <p>I would like to format a float number as a percent-value with JFormattedTextField that allows inputs from 0 to 100 percent (converted to 0.0f-1.0f), always shows the percent sign and disallows any invalid characters.</p>
  
  <p>Now I have experimented a bit with NumberFormat.getPercentInstance() and the NumberFormatter attributes but without success.</p>
  
  <p>Is there a way to create a JFormattedTextField that obeys to these rules with the standard classes? Or do I have to implement my own NumberFormatter?</p>
  
  <p>That's what I have so far (no way to input 100%, entering a 0 breaks it completly):</p>
  
  <pre><code>public class MaskFormatterTest {
      public static void main(String[] args) throws Exception {
          JFrame frame = new JFrame("Test");
          frame.setLayout(new BorderLayout());
          frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  
          NumberFormat format = NumberFormat.getPercentInstance();
          NumberFormatter formatter = new NumberFormatter(format);
          formatter.setMaximum(1.0f);
          formatter.setMinimum(0.0f);
          formatter.setAllowsInvalid(false);
          formatter.setOverwriteMode(true);
          JFormattedTextField tf = new JFormattedTextField(formatter);
          tf.setColumns(20);
          tf.setValue(0.56f);
  
          frame.add(tf);
          frame.pack();
          frame.setVisible(true);
      }
  }
  </code></pre>