public class JavaNumberFormatter
extends javax.swing.text.DefaultFormatter
ScaledNumberFormatter
is used to format numbers written in the
Java programming syntax.Constructor and Description |
---|
JavaNumberFormatter()
Creates a
NumberFormatter with the a default
NumberFormat instance obtained from
NumberFormat.getNumberInstance() . |
JavaNumberFormatter(double min,
double max,
double multiplier)
Creates a NumberFormatter with the specified Format instance.
|
JavaNumberFormatter(double min,
double max,
double multiplier,
boolean allowsNullValue)
Creates a NumberFormatter with the specified Format instance.
|
JavaNumberFormatter(double min,
double max,
double multiplier,
boolean allowsNullValue,
java.lang.String unit)
Creates a NumberFormatter with the specified Format instance.
|
Modifier and Type | Method and Description |
---|---|
static javax.swing.JFormattedTextField.AbstractFormatterFactory |
createFormatterFactory(double min,
double max,
double multiplier)
Convenience method for creating a formatter factory with a
ScalableNumberFormatter and a Java-style DecimalFormat. |
static javax.swing.JFormattedTextField.AbstractFormatterFactory |
createFormatterFactory(double min,
double max,
double multiplier,
boolean allowsNullValue)
Convenience method for creating a formatter factory with a
ScalableNumberFormatter and a Java-style DecimalFormat. |
static javax.swing.JFormattedTextField.AbstractFormatterFactory |
createFormatterFactory(double min,
double max,
double multiplier,
boolean allowsNullValue,
java.lang.String unit)
Convenience method for creating a formatter factory with a
ScalableNumberFormatter and a Java-style DecimalFormat. |
boolean |
getAllowsNullValue()
Returns true if null values are allowed.
|
java.lang.Comparable |
getMaximum()
Returns the maximum permissible value.
|
int |
getMaximumFractionDigits()
Gets the maximum number of digits allowed in the fraction portion of a
number.
|
int |
getMaximumIntegerDigits()
Gets the maximum number of digits allowed in the integer portion of a
number.
|
java.lang.Comparable |
getMinimum()
Returns the minimum permissible value.
|
int |
getMinimumFractionDigits()
Returns true if null values are allowed.
|
int |
getMinimumIntegerDigits()
Gets the minimum number of digits allowed in the integer portion of a
number.
|
int |
getMinimumNegativeExponent()
Gets the minimum negative exponent value for scientific notation.
|
int |
getMinimumPositiveExponent()
Gets the minimum positive exponent value for scientific notation.
|
double |
getMultiplier()
Gets the multiplier for use in percent, per mille, and similar formats.
|
java.lang.String |
getUnit()
If non-null the unit string is appended to the value.
|
boolean |
isUsesScientificNotation()
Returns true if scientific notation is used.
|
void |
setAllowsNullValue(boolean newValue)
Allows/Disallows null values.
|
void |
setMaximum(java.lang.Comparable max)
Sets the maximum permissible value.
|
void |
setMaximumFractionDigits(int newValue)
Sets the maximum number of digits allowed in the fraction portion of a
number.
|
void |
setMaximumIntegerDigits(int newValue)
Sets the maximum number of digits allowed in the integer portion of a
number.
|
void |
setMinimum(java.lang.Comparable minimum)
Sets the minimum permissible value.
|
void |
setMinimumFractionDigits(int newValue)
Specifies whether ".0" is appended to double and float
values.
|
void |
setMinimumIntegerDigits(int newValue)
Sets the minimum number of digits allowed in the integer portion of a
number.
|
void |
setMinimumNegativeExponent(int newValue)
Sets the minimum negative exponent value for scientific notation.
|
void |
setMinimumPositiveExponent(int newValue)
Sets the minimum positive exponent value for scientific notation.
|
void |
setMultiplier(double newValue)
Sets the multiplier for use in percent, per mille, and similar formats.
|
void |
setUnit(java.lang.String value)
If non-null the unit string is appended to the value.
|
void |
setUsesScientificNotation(boolean newValue)
Sets whether scientific notation is used.
|
java.lang.Object |
stringToValue(java.lang.String text)
Returns the
Object representation of the
String text . |
java.lang.String |
valueToString(java.lang.Object value)
Returns a String representation of the Object
value . |
clone, getAllowsInvalid, getCommitsOnValidEdit, getDocumentFilter, getNavigationFilter, getOverwriteMode, getValueClass, install, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass
public JavaNumberFormatter()
NumberFormatter
with the a default
NumberFormat
instance obtained from
NumberFormat.getNumberInstance()
.public JavaNumberFormatter(double min, double max, double multiplier)
public JavaNumberFormatter(double min, double max, double multiplier, boolean allowsNullValue)
public JavaNumberFormatter(double min, double max, double multiplier, boolean allowsNullValue, java.lang.String unit)
public void setMinimum(java.lang.Comparable minimum)
valueClass
has
not been specified, and minimum
is non null, the
valueClass
will be set to that of the class of
minimum
.minimum
- Minimum legal value that can be inputDefaultFormatter.setValueClass(java.lang.Class<?>)
public java.lang.Comparable getMinimum()
public void setMaximum(java.lang.Comparable max)
valueClass
has
not been specified, and max
is non null, the
valueClass
will be set to that of the class of
max
.max
- Maximum legal value that can be inputDefaultFormatter.setValueClass(java.lang.Class<?>)
public java.lang.Comparable getMaximum()
public void setMultiplier(double newValue)
public double getMultiplier()
public void setAllowsNullValue(boolean newValue)
newValue
- public boolean getAllowsNullValue()
public void setMinimumFractionDigits(int newValue)
newValue
- public int getMinimumFractionDigits()
public java.lang.String valueToString(java.lang.Object value) throws java.text.ParseException
value
.
This invokes format
on the current Format
.valueToString
in class javax.swing.text.DefaultFormatter
value
- Value to convertjava.text.ParseException
- if there is an error in the conversionpublic java.lang.Object stringToValue(java.lang.String text) throws java.text.ParseException
Object
representation of the
String
text
.stringToValue
in class javax.swing.text.DefaultFormatter
text
- String
to convertObject
representation of textjava.text.ParseException
- if there is an error in the conversionpublic void setUnit(java.lang.String value)
public java.lang.String getUnit()
public int getMinimumIntegerDigits()
public void setMinimumIntegerDigits(int newValue)
public int getMaximumIntegerDigits()
public void setMaximumIntegerDigits(int newValue)
public int getMaximumFractionDigits()
public void setMaximumFractionDigits(int newValue)
public int getMinimumNegativeExponent()
public void setMinimumNegativeExponent(int newValue)
public int getMinimumPositiveExponent()
public void setMinimumPositiveExponent(int newValue)
public boolean isUsesScientificNotation()
public void setUsesScientificNotation(boolean newValue)
public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min, double max, double multiplier)
ScalableNumberFormatter
and a Java-style DecimalFormat.
Doesn't allow null values and doesn't append ".0" to double and float values.public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min, double max, double multiplier, boolean allowsNullValue)
ScalableNumberFormatter
and a Java-style DecimalFormat.public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min, double max, double multiplier, boolean allowsNullValue, java.lang.String unit)
ScalableNumberFormatter
and a Java-style DecimalFormat.