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