1 33 34 package com.nqadmin.swingSet.formatting; 35 36 import javax.swing.JFormattedTextField.AbstractFormatterFactory; 37 38 import java.text.NumberFormat ; 39 import javax.swing.text.NumberFormatter ; 40 import java.util.Locale ; 41 import javax.swing.JTextField ; 42 43 47 48 public class SSNumericField extends SSFormattedTextField { 49 50 private int precision = 1; 51 private int decimals = 0; 52 53 56 private int minimumIntegerDigits; 57 58 59 public SSNumericField() { 60 this(new SSNumericFormatterFactory()); 61 } 62 63 public SSNumericField(int precision, int decimals) { 64 this(new SSNumericFormatterFactory(precision, decimals)); 65 } 66 67 68 public SSNumericField(javax.swing.JFormattedTextField.AbstractFormatterFactory factory) { 69 super(factory); 70 this.setHorizontalAlignment(JTextField.RIGHT); 71 } 72 73 public int getPrecision() { 74 return precision; 75 } 76 77 public int getDecimals() { 78 return decimals; 79 } 80 81 public void setPrecision(int precision) { 82 this.precision = precision; 83 this.setFormatterFactory(new SSNumericFormatterFactory(precision, decimals)); 84 } 85 86 public void setDecimals(int decimals) { 87 this.decimals = decimals; 88 } 89 90 94 public int getMinimumIntegerDigits() { 95 96 return this.minimumIntegerDigits; 97 } 98 99 103 public void setMinimumIntegerDigits(int minimumIntegerDigits) { 104 105 this.minimumIntegerDigits = minimumIntegerDigits; 106 } 107 } 108 109 124 | Popular Tags |