public class DefaultFormatter extends JFormattedTextField.AbstractFormatter implements Cloneable, Serializable
DefaultFormatter格式化任意对象。 
       格式化是通过调用toString方法来完成的。 
       为了将值转换为String,您的类必须提供一个构造函数,它接受一个String参数。 
       如果没有找到接受String的单个参数构造函数,则返回的值将是传递给stringToValue的String。 
        DefaultFormatter的DefaultFormatter不能用于JFormattedTextField的多个JFormattedTextField 。 要获得已配置的DefaultFormatter的副本,请使用clone方法。 
 警告:此类的序列化对象与将来的Swing版本不兼容。 当前的序列化支持适用于运行相同版本的Swing的应用程序之间的短期存储或RMI。 从1.4开始,对所有JavaBeans的长期存储的支持已被添加到java.beans包中。 请参阅XMLEncoder 。 
JFormattedTextField.AbstractFormatter 
       | Constructor and Description | 
|---|
| DefaultFormatter()
              创建一个DefaultFormatter。 
             | 
| Modifier and Type | Method and Description | 
|---|---|
| Object | clone()
              创建一个DefaultFormatter的副本。 
             | 
| boolean | getAllowsInvalid()
              返回正在编辑的值是否允许在一段时间内无效。 
             | 
| boolean | getCommitsOnValidEdit()
              当编辑内容发布回返回 
              JFormattedTextField。 | 
| protected DocumentFilter | getDocumentFilter()
              返回 
              DocumentFilter用于限制可以输入到JFormattedTextField。 | 
| protected NavigationFilter | getNavigationFilter()
              返回 
              NavigationFilter用于限制光标放置的位置。 | 
| boolean | getOverwriteMode()
              返回插入字符时的行为。 
             | 
| 类<?> | getValueClass()
              返回用于创建新对象的类。 
             | 
| void | install(JFormattedTextField ftf)
              将 
              DefaultFormatter安装到特定的JFormattedTextField。 | 
| void | setAllowsInvalid(boolean allowsInvalid)
              设置被编辑的值是否允许在一段时间内无效(即 
              stringToValue抛出ParseException)。 | 
| void | setCommitsOnValidEdit(boolean commit)
              编辑编辑时设置为 
              JFormattedTextField。 | 
| void | setOverwriteMode(boolean overwriteMode)
              配置插入字符时的行为。 
             | 
| void | setValueClass(类<?> valueClass)
              设置用于创建新对象的类。 
             | 
| Object | stringToValue(String string)
              通过使用String参数的构造函数将String中的传递转换为 
              getValueClass的实例。 | 
| String | valueToString(Object value)
              通过 
              toString方法将Object中传递的对象转换为字符串。 | 
getActions, getFormattedTextField, invalidEdit, setEditValid, uninstallpublic void install(JFormattedTextField ftf)
DefaultFormatter安装到特定的JFormattedTextField 。 
           这将调用valueToString将当前值从JFormattedTextField转换为字符串。 
           那么这将安装Action从s getActions ,该DocumentFilter从返回getDocumentFilter和NavigationFilter从返回getNavigationFilter到JFormattedTextField 。 
            子类通常只需要覆盖这个,如果他们希望在JFormattedTextField上安装其他监听JFormattedTextField 。 
 如果有一个ParseException将当前值转换为字符串,则将文本设置为空字符串,并将JFormattedTextField标记为无效状态。 
 虽然这是一种公共方法,但这通常仅适用于JFormattedTextField的JFormattedTextField 。 JFormattedTextField将在值更改或其内部状态更改的适当时候调用此方法。 
install在 
            JFormattedTextField.AbstractFormatter 
           ftf - JFormattedTextField格式化,可能为null表示从当前JFormattedTextField卸载。 
           public void setCommitsOnValidEdit(boolean commit)
JFormattedTextField 。 
           如果为true,则在每次有效的编辑之后调用commitEdit (任何时候编辑文本)。 
           另一方面,如果这是错误的, DefaultFormatter不发布编辑回JFormattedTextField 。 
           因此,只有时间价值JFormattedTextField将改变时commitEdit是在调用JFormattedTextField ,按下或焦点离开时,通常输入JFormattedTextField 。 
          commit - 用于指示何时将编辑提交回JTextComponent 
           public boolean getCommitsOnValidEdit()
JFormattedTextField 。 
          public void setOverwriteMode(boolean overwriteMode)
overwriteMode为true(默认值),新的字符将覆盖模型中的现有字符。 
          overwriteMode - 指示是否使用覆盖或重击模式 
           public boolean getOverwriteMode()
public void setAllowsInvalid(boolean allowsInvalid)
stringToValue抛出ParseException )。 
           允许用户临时输入无效值通常是方便的。 
          allowsInvalid - 用于指示编辑后的值是否始终有效 
           public boolean getAllowsInvalid()
public void setValueClass(类<?> valueClass)
valueClass - 用于从stringToValue构造返回值的类 
           public 类<?> getValueClass()
public Object stringToValue(String string) throws ParseException
getValueClass的实例。 
           如果getValueClass返回null, JFormattedTextField将使用JFormattedTextField中的当前值的Class。 
           如果这是null,将返回一个String。 
           如果构造函数引发异常,则会抛出ParseException 。 
           如果没有单个参数String构造函数,则返回string 。 
          stringToValue在 
            JFormattedTextField.AbstractFormatter 
           string - 要转换的字符串 
           ParseException - 如果转换中有错误 
           public String valueToString(Object value) throws ParseException
toString方法将Object中传递的对象转换为字符串。 
          valueToString在 
            JFormattedTextField.AbstractFormatter 
           value - 要转换的价值 
           ParseException - 转换中是否有错误 
           protected DocumentFilter getDocumentFilter()
DocumentFilter用于限制可以输入到 
           JFormattedTextField 。 
          getDocumentFilter在 
            JFormattedTextField.AbstractFormatter类 
           protected NavigationFilter getNavigationFilter()
NavigationFilter 。 
          getNavigationFilter在 
            JFormattedTextField.AbstractFormatter 
           public Object clone() throws CloneNotSupportedException
clone在 
            JFormattedTextField.AbstractFormatter 
           CloneNotSupportedException - 如果对象的类不支持Cloneable接口。 
            覆盖clone方法的子类也可以抛出此异常以指示实例无法克隆。 
           Cloneable 
            Submit a bug or feature 
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
 Copyright © 1993, 2014, Oracle and/or its affiliates. All rights reserved.