📄 formattedtextfield.html
字号:
<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/DefaultFormatterFactory.html">DefaultFormatterFactory</a> </td> <td>The formatter factory normally used. Dishes out formatters based on details such as the passed-in parameters and focus state. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/DefaultFormatter.html">DefaultFormatter</a> </td> <td>Subclass of <code>JFormattedTextField.AbstractFormatter</code> that formats arbitrary objects using the <code>toString</code> method. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/MaskFormatter.html">MaskFormatter</a> </td> <td>Subclass of <code>DefaultFormatter</code> that formats and edits strings using a specified character mask. (For example, 7-digit phone numbers can be specified using "###-####".) </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/InternationalFormatter.html">InternationalFormatter</a> </td> <td>Subclass of <code>DefaultFormatter</code> that uses an instance of <code>java.text.Format</code> to handle conversion to and from a <code>String</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/NumberFormatter.html">NumberFormatter</a> </td> <td>Subclass of <code>InternationalFormatter</code> that supports number formats using an instance of <code>NumberFormat</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/DateFormatter.html">DateFormatter</a> </td> <td>Subclass of <code>InternationalFormatter</code> that supports date formats using an instance of <code>DateFormat</code>. </td> </tr></table><p><table border=1><caption><a name="formattedtextfieldapi">JFormattedTextField Methods</a></caption><tr><th align=left>Method or Constructor</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#JFormattedTextField()">JFormattedTextField()</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#JFormattedTextField(java.lang.Object)">JFormattedTextField(Object)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#JFormattedTextField(java.text.Format)">JFormattedTextField(Format)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#JFormattedTextField(javax.swing.JFormattedTextField.AbstractFormatter)">JFormattedTextField(AbstractFormatter)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#JFormattedTextField(javax.swing.JFormattedTextField.AbstractFormatterFactory)">JFormattedTextField(AbstractFormatterFactory)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#JFormattedTextField(javax.swing.JFormattedTextField.AbstractFormatterFactory, java.lang.Object)">JFormattedTextField(AbstractFormatterFactory, Object)</a> </td> <td>Create a new formatted text field. The <code>Object</code> argument, if present, specifies the initial value of the field and causes an appropriate formatter factory to be created. The <code>Format</code> or <code>AbstractFormatter</code>argument specifies the format or formatter to be used for the field, causing an appropriate formatter factory to be created. The <code>AbstractFormatterFactory</code> argument specifies the formatter factory to be used, which determines which formatters are used for the field. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#setValue(java.lang.Object)">void setValue(Object)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#getValue()">Object getValue()</a> </td> <td>Set or get the value of the formatted text field. You must cast the return type based on how the <code>JFormattedTextField</code> has been configured. If the formatter hasn't been set yet, invoking <code>setValue</code> sets the formatter to one returned by the field's formatter factory. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#setFormatterFactory(javax.swing.JFormattedTextField.AbstractFormatterFactory)">void setFormatterFactory(AbstractFormatterFactory)</a> </td> <td>Set the object that determines the formatters used for the formatted text field. It is often an instance of <code>DefaultFormatterFactory</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#getFormatter()">AbstractFormatter getFormatter()</a> </td> <td>Get the formatter of the formatted text field. It is often an instance of <code>DefaultFormatter</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#setFocusLostBehavior(int)">void setFocusLostBehavior(int)</a> </td> <td> Specifies what should happen when the field loses the focus. Possible values are defined in <code>JFormattedTextField</code> as <code>COMMIT_OR_REVERT</code> (the default), <code>COMMIT</code> (commit if valid, otherwise leave everything the same), <code>PERSIST</code> (do nothing), and <code>REVERT</code> (change the text to reflect the value). </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#commitEdit()">void commitEdit()</a> </td> <td>Sets the value to the object represented by the field's text (as determined by the field's formatter). If the text is invalid, the value remains the same and a<a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/java/text/ParseException.html"><code>ParseException</code></a> is thrown. </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JFormattedTextField.html#isEditValid()">boolean isEditValid()</a> </td> <td>Returns true if the formatter considers the current text to be valid (as determined by the field's formatter). </td> </tr></table><p><table border=1><caption><a name="defaultformatterapi">DefaultFormatter Options</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/DefaultFormatter.html#setCommitsOnValidEdit(boolean)">void setCommitsOnValidEdit(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/DefaultFormatter.html#getCommitsOnValidEdit()">boolean getCommitsOnValidEdit()</a> </td> <td>Set or get when edits are pushed back to the <code>JFormattedTextField</code>. If <code>true</code>, <code>commitEdit</code> is invoked after every valid edit. This property is <code>false</code> by default. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/DefaultFormatter.html#setOverwriteMode(boolean)">void setOverwriteMode(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/DefaultFormatter.html#getOverwriteMode()">boolean getOverwriteMode()</a> </td> <td>Set or get the behavior when inserting characters. If <code>true</code>, new characters overwrite existing characters in the model as they are inserted. The default value of this property is <code>true</code> in <code>DefaultFormatter</code> (and thus in <code>MaskFormatter</code>) and <code>false</code> in <code>InternationalFormatter</code> (and thus in <code>DateFormatter</code> and <code>NumberFormatter</code>). </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/DefaultFormatter.html#setAllowsInvalid(boolean)">void setAllowsInvalid(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/text/DefaultFormatter.html#getAllowsInvalid()">boolean getAllowsInvalid()</a> </td> <td>Set or get whether the value being edited is allowed to be invalid for a length of time. It is often convenient to allow the user to enter invalid values until a commit is attempted. <code>DefaultFormatter</code> initializes this property to<code>true</code>. Of the standard Swing formatters, only <code>MaskFormatter</code> sets it to <code>false</code>. </td> </tr></table></blockquote><h3><a name="eg">Examples that Use Formatted Text Fields</a></h3><blockquote>A few of our examples use formatted text fields.<p><table summary="layout"><tr><th align=left> Example</th><th align=left> Where Described</th><th align=left> Notes</th></tr><tr valign = top><td> <a href="examples/index.html#FormattedTextFieldDemo">FormattedTextFieldDemo</a></td><td> This section</td><td> Uses four formatted text fields.</td></tr><tr valign = top><td> <a href="examples/index.html#SpinnerDemo">SpinnerDemo</a></td><td> <a href="spinner.html">How to Use Spinners</a></td><td> Customizes the appearance of the formatted text fields used by two spinners.</td></tr><tr valign = top><td> <a href="examples/index.html#SliderDemo3">SliderDemo3</a></td><td> <a href="slider.html">How to Use Sliders</a></td><td> Pairs a formatted text field with a slider to allow editing of an integer value.</td></tr><tr valign = top><td> <a href="examples/index.html#Converter">Converter</a></td><td> <a href="model.html">Using Models</a></td><td> Each <code>ConversionPanel</code> pairs a formatted text field with a slider.</td></tr><tr valign = top><td> CelsiusConverter2<br><font color=gray>[PENDING:When the 1.4 version of this example is added, there will be a link to it.]</font></td><td>Nowhere yet</td><td> Uses a formatted text field to let the user enter a decimal number.</td></tr><tr valign = top><td> <a href="examples/index.html#TextInputDemo">TextInputDemo</a></td><td> This section</td><td> Shows how to use text fields, spinners, and formatted text fields together, and demonstrates how to use <code>MaskFormatter</code>. Includes code for selecting the text of the field that has just gotten the focus.</td></tr><tr valign = top><td> <a href="examples/index.html#FormatterFactoryDemo">FormatterFactoryDemo</a></td><td> This section</td><td> A variation on FormattedTextFieldDemo that uses formatter factories to specify multiple formatters for two formatted text fields.</td></tr><tr><td valign=top>RegexFormatter</td><td valign=top><a class="OutsideLink" target="_blank" href="http://java.sun.com/products/jfc/tsc/articles/reftf">Regular Expression Based AbstractFormatter</a> (in<a class="OutsideLink" target="_blank" href="http://java.sun.com/products/jfc/tsc"><em>The Swing Connection</em></a></td><td valign=top>A regular expression formatterthat you can use.Includes source code and information on how it was implemented.</td></table> </blockquote> <div class=NavBit> <a target=_top href=filechooser.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=frame.html>Next »</a> </div> </div> <div id=Footer><div id=TagNotes> Problems with the examples? Try <a target="_blank" href=../../information/run-examples.html>Compiling and Running the Examples: FAQs</a>. <br> Complaints? Compliments? Suggestions? <a target="_blank" href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give us your feedback</a>.<br><br> <a target="_blank" href="../../information/copyright.html">Copyright</a> 1995-2006 Sun Microsystems, Inc. All rights reserved. <span id=Download></span></div> </div> <div class=PrintHeaders> <b>Previous page:</b> How to Use File Choosers <br><b>Next page:</b> How to Make Frames (Main Windows) </div> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -