| javax.swing.text.DefaultFormatter javax.swing.text.InternationalFormatter javax.swing.text.NumberFormatter
NumberFormatter | public class NumberFormatter extends InternationalFormatter (Code) | | 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) ):
- Pressing +/- (- is determined from the
DecimalFormatSymbols associated with the
DecimalFormat ) in any field but the exponent
field will attempt to change the sign of the number to
positive/negative.
- Pressing +/- (- is determined from the
DecimalFormatSymbols associated with the
DecimalFormat ) in the exponent field will
attemp to change the sign of the exponent to positive/negative.
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);
textFormatter.setOverwriteMode(true);
textFormatter.setAllowsInvalid(false);
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,
NumberFormatter.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 .
version: 1.4 03/05/01 since: 1.4 |
Constructor Summary | |
public | NumberFormatter() Creates a NumberFormatter with the a default
NumberFormat instance obtained from
NumberFormat.getNumberInstance() . | public | NumberFormatter(NumberFormat format) Creates a NumberFormatter with the specified Format instance. |
Method Summary | |
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(DocumentFilter.FilterBypass fb, int offset, int length, String string, AttributeSet attr) 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. | Object | stringToValue(String text, Format f) Invokes parseObject on f , returning
its value. |
NumberFormatter | public NumberFormatter()(Code) | | Creates a NumberFormatter with the a default
NumberFormat instance obtained from
NumberFormat.getNumberInstance() .
|
NumberFormatter | public NumberFormatter(NumberFormat format)(Code) | | Creates a NumberFormatter with the specified Format instance.
Parameters: format - Format used to dictate legal values |
isLegalInsertText | boolean isLegalInsertText(String text)(Code) | | 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.
|
isLiteral | boolean isLiteral(Map attrs)(Code) | | Subclassed to treat the decimal separator, grouping separator,
exponent symbol, percent, permille, currency and sign as literals.
|
isNavigatable | boolean isNavigatable(int index)(Code) | | Subclassed to make the decimal separator navigatable, as well
as making the character between the integer field and the next
field navigatable.
|
setFormat | public void setFormat(Format format)(Code) | | 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.
Parameters: format - NumberFormat instance used to dictate legal values |
Methods inherited from javax.swing.text.InternationalFormatter | Object adjustValue(Object value, Map attributes, Object field, int direction) throws BadLocationException, ParseException(Code)(Java Doc) boolean canIncrement(Object field, int cursorPosition)(Code)(Java Doc) boolean canReplace(ReplaceHolder rh)(Code)(Java Doc) public Object clone() throws CloneNotSupportedException(Code)(Java Doc) protected Action[] getActions()(Code)(Java Doc) Object getAdjustField(int start, Map attributes)(Code)(Java Doc) int getAttributeStart(AttributedCharacterIterator.Attribute id)(Code)(Java Doc) Map getAttributes(int index)(Code)(Java Doc) char getBufferedChar(int index)(Code)(Java Doc) public Format.Field[] getFields(int offset)(Code)(Java Doc) public Format getFormat()(Code)(Java Doc) AttributedCharacterIterator getIterator()(Code)(Java Doc) char getLiteral(int index)(Code)(Java Doc) int getLiteralCountTo(int index)(Code)(Java Doc) public Comparable getMaximum()(Code)(Java Doc) public Comparable getMinimum()(Code)(Java Doc) ReplaceHolder getReplaceHolder(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs)(Code)(Java Doc) boolean getSupportsIncrement()(Code)(Java Doc) public void install(JFormattedTextField ftf)(Code)(Java Doc) boolean isLiteral(int index)(Code)(Java Doc) boolean isLiteral(Map attributes)(Code)(Java Doc) boolean isNavigatable(int offset)(Code)(Java Doc) boolean isValidMask()(Code)(Java Doc) boolean isValidValue(Object value, boolean wantsCCE)(Code)(Java Doc) void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException(Code)(Java Doc) boolean replace(ReplaceHolder rh) throws BadLocationException(Code)(Java Doc) void resetValue(Object value) throws BadLocationException, ParseException(Code)(Java Doc) void selectField(Object f, int count)(Code)(Java Doc) public void setFormat(Format format)(Code)(Java Doc) public void setMaximum(Comparable max)(Code)(Java Doc) public void setMinimum(Comparable minimum)(Code)(Java Doc) public Object stringToValue(String text) throws ParseException(Code)(Java Doc) Object stringToValue(String text, Format f) throws ParseException(Code)(Java Doc) void updateMask()(Code)(Java Doc) void updateMaskIfNecessary()(Code)(Java Doc) void updateValue(Object value)(Code)(Java Doc) public String valueToString(Object value) throws ParseException(Code)(Java Doc)
|
Fields inherited from javax.swing.text.DefaultFormatter | transient ReplaceHolder replaceHolder(Code)(Java Doc)
|
Methods inherited from javax.swing.text.DefaultFormatter | boolean canReplace(ReplaceHolder rh)(Code)(Java Doc) public Object clone() throws CloneNotSupportedException(Code)(Java Doc) void commitEdit() throws ParseException(Code)(Java Doc) public boolean getAllowsInvalid()(Code)(Java Doc) public boolean getCommitsOnValidEdit()(Code)(Java Doc) protected DocumentFilter getDocumentFilter()(Code)(Java Doc) int getInitialVisualPosition()(Code)(Java Doc) protected NavigationFilter getNavigationFilter()(Code)(Java Doc) int getNextCursorPosition(int offset, int direction)(Code)(Java Doc) int getNextVisualPositionFrom(JTextComponent text, int pos, Position.Bias bias, int direction, Position.Bias[] biasRet) throws BadLocationException(Code)(Java Doc) public boolean getOverwriteMode()(Code)(Java Doc) ReplaceHolder getReplaceHolder(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs)(Code)(Java Doc) String getReplaceString(int offset, int deleteLength, String replaceString)(Code)(Java Doc) public Class> getValueClass()(Code)(Java Doc) public void install(JFormattedTextField ftf)(Code)(Java Doc) boolean isLegalInsertText(String text)(Code)(Java Doc) boolean isNavigatable(int offset)(Code)(Java Doc) boolean isValidEdit(ReplaceHolder rh)(Code)(Java Doc) void moveDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias)(Code)(Java Doc) void positionCursorAtInitialLocation()(Code)(Java Doc) void replace(DocumentFilter.FilterBypass fb, int offset, int length, String text, AttributeSet attrs) throws BadLocationException(Code)(Java Doc) boolean replace(ReplaceHolder rh) throws BadLocationException(Code)(Java Doc) void repositionCursor(int offset, int direction)(Code)(Java Doc) public void setAllowsInvalid(boolean allowsInvalid)(Code)(Java Doc) public void setCommitsOnValidEdit(boolean commit)(Code)(Java Doc) void setDot(NavigationFilter.FilterBypass fb, int dot, Position.Bias bias)(Code)(Java Doc) public void setOverwriteMode(boolean overwriteMode)(Code)(Java Doc) public void setValueClass(Class> valueClass)(Code)(Java Doc) public Object stringToValue(String string) throws ParseException(Code)(Java Doc) void updateValue()(Code)(Java Doc) void updateValue(Object value)(Code)(Java Doc) public String valueToString(Object value) throws ParseException(Code)(Java Doc)
|
|
|