Home » openjdk-7 » javax » swing » text » [javadoc | source]
public class: NumberFormatter [javadoc | source]

All Implemented Interfaces:
    Cloneable, Serializable

Direct Known Subclasses:

NumberFormatter subclasses InternationalFormatter adding special behavior for numbers. Among the specializations are (these are only used if the NumberFormatter does not display invalid nubers, eg setAllowsInvalid(false)):

If you are displaying scientific numbers, you may wish to turn on overwrite mode, setOverwriteMode(true). For example:

DecimalFormat decimalFormat = new DecimalFormat("0.000E0");
NumberFormatter textFormatter = new NumberFormatter(decimalFormat);

If you are going to allow the user to enter decimal values, you should either force the DecimalFormat to contain at least one decimal (#.0###), or allow the value to be invalid setAllowsInvalid(true). Otherwise users may not be able to input decimal values.

NumberFormatter provides slightly different behavior to stringToValue than that of its superclass. If you have specified a Class for values, #setValueClass , that is one of of Integer, Long, Float, Double, Byte or Short and the Format's parseObject returns an instance of Number, the corresponding instance of the value class will be created using the constructor appropriate for the primitive type the value class represents. For example: setValueClass(Integer.class) will cause the resulting value to be created via new Integer(((Number)formatter.parseObject(string)).intValue()). This is typically useful if you wish to set a min/max value as the various Number implementations are generally not comparable to each other. This is also useful if for some reason you need a specific Number implementation for your values.

Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see java.beans.XMLEncoder .

Fields inherited from javax.swing.text.DefaultFormatter:
 public NumberFormatter() 
 public NumberFormatter(NumberFormat format) 
    Creates a NumberFormatter with the specified Format instance.
    format - Format used to dictate legal values
Method from javax.swing.text.NumberFormatter Summary:
isLegalInsertText,   isLiteral,   isNavigatable,   replace,   setFormat,   stringToValue
Methods from javax.swing.text.InternationalFormatter:
adjustValue,   canIncrement,   canReplace,   clone,   getActions,   getAdjustField,   getAttributeStart,   getAttributes,   getBufferedChar,   getFields,   getFormat,   getIterator,   getLiteral,   getLiteralCountTo,   getMaximum,   getMinimum,   getReplaceHolder,   getSupportsIncrement,   install,   isLiteral,   isLiteral,   isNavigatable,   isValidMask,   isValidValue,   replace,   replace,   resetValue,   selectField,   setFormat,   setMaximum,   setMinimum,   stringToValue,   stringToValue,   updateMask,   updateMaskIfNecessary,   updateValue,   valueToString
Methods from javax.swing.text.DefaultFormatter:
canReplace,   clone,   commitEdit,   getAllowsInvalid,   getCommitsOnValidEdit,   getDocumentFilter,   getInitialVisualPosition,   getNavigationFilter,   getNextCursorPosition,   getNextVisualPositionFrom,   getOverwriteMode,   getReplaceHolder,   getReplaceString,   getValueClass,   install,   isLegalInsertText,   isNavigatable,   isValidEdit,   moveDot,   positionCursorAtInitialLocation,   replace,   replace,   repositionCursor,   setAllowsInvalid,   setCommitsOnValidEdit,   setDot,   setOverwriteMode,   setValueClass,   stringToValue,   updateValue,   updateValue,   valueToString
Methods from javax.swing.JFormattedTextField$AbstractFormatter:
clone,   getActions,   getDocumentFilter,   getFormattedTextField,   getNavigationFilter,   install,   invalidEdit,   setEditValid,   stringToValue,   uninstall,   valueToString
Methods from java.lang.Object:
clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   wait
Method from javax.swing.text.NumberFormatter Detail:
 boolean isLegalInsertText(String text) 
    Subclassed to return false if text contains in an invalid character to insert, that is, it is not a digit (Character.isDigit()) and not one of the characters defined by the DecimalFormatSymbols.
 boolean isLiteral(Map attrs) 
    Subclassed to treat the decimal separator, grouping separator, exponent symbol, percent, permille, currency and sign as literals.
 boolean isNavigatable(int index) 
    Subclassed to make the decimal separator navigatable, as well as making the character between the integer field and the next field navigatable.
  void replace(FilterBypass fb,
    int offset,
    int length,
    String string,
    AttributeSet attr) throws BadLocationException 
    Overriden to toggle the value if the positive/minus sign is inserted.
 public  void setFormat(Format format) 
    Sets the format that dictates the legal values that can be edited and displayed.

    If you have used the nullary constructor the value of this property will be determined for the current locale by way of the NumberFormat.getNumberInstance() method.

 Object stringToValue(String text,
    Format f) throws ParseException 
    Invokes parseObject on f, returning its value.