1 33 34 package com.nqadmin.swingSet.formatting; 35 36 import javax.swing.text.NumberFormatter ; 37 import java.text.NumberFormat ; 38 import java.util.Locale ; 39 40 import java.io.Serializable ; 41 import java.text.ParseException ; 42 import javax.swing.JFormattedTextField ; 43 44 45 49 public class SSNumericFormatterFactory extends javax.swing.text.DefaultFormatterFactory implements Serializable { 50 51 public SSNumericFormatterFactory() { 52 this.setDefaultFormatter(new NumberFormatter (NumberFormat.getInstance())); 53 this.setNullFormatter(null); 54 this.setEditFormatter(new NumberFormatter (NumberFormat.getInstance(Locale.US))); 55 this.setDisplayFormatter(new NumberFormatter (NumberFormat.getInstance())); 56 } 57 58 public SSNumericFormatterFactory(int precision, int decimals) { 59 NumberFormat nfd = NumberFormat.getInstance(Locale.US); 60 nfd.setMaximumFractionDigits(decimals); 61 nfd.setMinimumFractionDigits(decimals); 62 63 nfd.setMaximumIntegerDigits(precision); 64 nfd.setMinimumIntegerDigits(1); 65 66 this.setDefaultFormatter(new NumberFormatter (NumberFormat.getInstance())); 67 this.setNullFormatter(null); 68 this.setEditFormatter(new NumberFormatter (NumberFormat.getInstance(Locale.US))); 69 this.setDisplayFormatter(new NumberFormatter (nfd)); 70 71 } 72 } 73 74 89 | Popular Tags |