Thursday 15 July 2010

java - A JFormattedTextField to accept a currency format without decimals -


How do I code a JFormattedTextField to accept the currency format without decimals?

I have tried to find my answer everywhere, here, Oracle, Google, and code for being specific.

My question: How do I code a formatted text field to accept the currency format without decimals? The text field can accept value anywhere from $ 5 to $ 10,000,000. I would like to include it when needed, "This field will not be used for mathematical expressions, so there is no need to replace it with string.

Here is the code I am trying to use. This format does not allow me to enter any number in the formatted text field.

buildInfo method

  // buildInfo method information panel builds Private ZeroBinfo () {info = new JPanel (); GridLayout GL = New Grid Layout (3.1); Info.setLayout (GL); // Create panel, label, and text area for names of plaques p1 = new JPNL (); P1.setLayout (New Flow Layout (Flow Layout. Left)); Label 1 = new jlabel ("name of plazers:"); P1.add (label1); Text1 = new JTextField (20); P1.add (text1); // Create panel, label, and text field for the Playz amount = New JPNL (); P2.setLayout (New Flow Layout (Flow Layouts. LEFT)); Label 2 = new jlabell ("committed sum:"); P2.add (label2); Number formatting zodiac = number format.get cauverinstance (locale.US); Amount.setMaximumFractionDigits (0); NumberFormatter page = new numberformer (amount); PAmount.setMinimum (5.0); PAmount.setMaximum (10000000.0); PAmount.setAllowsInvalid (false); Text2 = new gestatetextfiled (pamount); Text2.setColumns (12); P2.add (text2); // Create panel, label and text area for charity; P3 = new jepineal (); P3.setLayout (New Flow Layout (Flow Layout. Left)); Label 3 = new JLABEL ("committed to donate:"); P3.add (label3); Text3 = new JTextField (20); P3.add (text3); // Add Panel Add Main Panel (P1); (P2) add; (P3); }    

Use

  no format format = Number format getCurrencyInstance (Locale.US); Format.setMaximumFractionDigits (0); NumberFormatter formatter = new numberformer (format); Formatter.setMinimum (5.0); Formatter.setMaximum (10000000.0); Formatter.setAllowsInvalid (false); Formatter.setOverwriteMode (true); JFormattedTextField field = new JFormattedTextField (formatter); Field.setValue (5.0);    

No comments:

Post a Comment