Java Doc for NumberFormatter.java in  » 6.0-JDK-Core » swing » javax » swing » text » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Home
Java Source Code / Java Documentation
1.6.0 JDK Core
2.6.0 JDK Modules
3.6.0 JDK Modules com.sun
4.6.0 JDK Modules com.sun.java
5.6.0 JDK Modules sun
6.6.0 JDK Platform
7.Ajax
8.Apache Harmony Java SE
9.Aspect oriented
10.Authentication Authorization
11.Blogger System
12.Build
13.Byte Code
14.Cache
15.Chart
16.Chat
17.Code Analyzer
18.Collaboration
19.Content Management System
20.Database Client
21.Database DBMS
22.Database JDBC Connection Pool
23.Database ORM
24.Development
25.EJB Server
26.ERP CRM Financial
27.ESB
28.Forum
29.Game
30.GIS
31.Graphic 3D
32.Graphic Library
33.Groupware
34.HTML Parser
35.IDE
36.IDE Eclipse
37.IDE Netbeans
38.Installer
39.Internationalization Localization
40.Inversion of Control
41.Issue Tracking
42.J2EE
43.J2ME
44.JBoss
45.JMS
46.JMX
47.Library
48.Mail Clients
49.Music
50.Net
51.Parser
52.PDF
53.Portal
54.Profiler
55.Project Management
56.Report
57.RSS RDF
58.Rule Engine
59.Science
60.Scripting
61.Search Engine
62.Security
63.Sevlet Container
64.Source Control
65.Swing Library
66.Template Engine
67.Test Coverage
68.Testing
69.UML
70.Web Crawler
71.Web Framework
72.Web Mail
73.Web Server
74.Web Services
75.Web Services apache cxf 2.2.6
76.Web Services AXIS2
77.Wiki Engine
78.Workflow Engines
79.XML
80.XML UI
Java Source Code / Java Documentation » 6.0 JDK Core » swing » javax.swing.text 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


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
 booleanisLegalInsertText(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.
 booleanisLiteral(Map attrs)
     Subclassed to treat the decimal separator, grouping separator, exponent symbol, percent, permille, currency and sign as literals.
 booleanisNavigatable(int index)
     Subclassed to make the decimal separator navigatable, as well as making the character between the integer field and the next field navigatable.
 voidreplace(DocumentFilter.FilterBypass fb, int offset, int length, String string, AttributeSet attr)
     Overriden to toggle the value if the positive/minus sign is inserted.
public  voidsetFormat(Format format)
     Sets the format that dictates the legal values that can be edited and displayed.
 ObjectstringToValue(String text, Format f)
     Invokes parseObject on f, returning its value.


Constructor Detail
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




Method Detail
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.



replace
void replace(DocumentFilter.FilterBypass fb, int offset, int length, String string, AttributeSet attr) throws BadLocationException(Code)
Overriden to toggle the value if the positive/minus sign is inserted.



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




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



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)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.