{@code}
name
attribute defines the name of the style which you can later use with {@link Skin#newTextField(String,float,String)}.font
attribute references a {@link BitmapFont} by name, to be used to render the text in the text fieldfontColor
attribute references a {@link Color} by name, to be used to render the text on the text fieldcursorPatch
attribute references a {@link NinePatch} by name, to be used to render the text field's cursorselectionRegion
attribute references a {@link TextureRegion} by name, to be used to highlight the textfield's selectionbackgroundPatch
attribute references a {@link NinePatch} by name, to be used as the text field'sbackgroundTextField<String> text = new TextField<String>(); text.setFieldLabel("Name"); text.setEmptyText("Enter your full name"); text.setAllowBlank(false); text.setMinLength(4);
A text editor component that can be bound to any bindable Property. The text editor supports both multiline and single line modes, default is one-line mode.
Since TextField
extends AbstractField
it implements the {@link com.vaadin.data.Buffered} interface. A TextField
isin write-through mode by default, so {@link com.vaadin.ui.AbstractField#setWriteThrough(boolean)} must be calledto enable buffering.
Every time the user types a key in the text field, one or more key events are sent to the text field. A KeyEvent
may be one of three types: keyPressed, keyReleased, or keyTyped. The properties of a key event indicate which of these types it is, as well as additional information about the event, such as what modifiers are applied to the key event and the time at which the event occurred.
The key event is passed to every KeyListener
or KeyAdapter
object which registered to receive such events using the component's addKeyListener
method. (KeyAdapter
objects implement the KeyListener
interface.)
It is also possible to fire an ActionEvent
. If action events are enabled for the text field, they may be fired by pressing the Return
key.
The TextField
class's processEvent
method examines the action event and passes it along to processActionEvent
. The latter method redirects the event to any ActionListener
objects that have registered to receive action events generated by this text field.
@version 1.85, 10/31/08
@author Sami Shaio
@see java.awt.event.KeyEvent
@see java.awt.event.KeyAdapter
@see java.awt.event.KeyListener
@see java.awt.event.ActionEvent
@see java.awt.Component#addKeyListener
@see java.awt.TextField#processEvent
@see java.awt.TextField#processActionEvent
@see java.awt.TextField#addActionListener
@since JDK1.0
TextField
is an editable text component that may be placed into a {@link Form Form}. It can be given a piece of text that is used as the initial value. A TextField
has a maximum size, which is the maximum number of characters that can be stored in the object at any time (its capacity). This limit is enforced when the TextField
instance is constructed, when the user is editing text within the TextField
, as well as when the application program calls methods on the TextField
that modify its contents. The maximum size is the maximum stored capacity and is unrelated to the number of characters that may be displayed at any given time. The number of characters displayed and their arrangement into rows and columns are determined by the device.
The implementation may place a boundary on the maximum size, and the maximum size actually assigned may be smaller than the application had requested. The value actually assigned will be reflected in the value returned by {@link #getMaxSize() getMaxSize()}. A defensively-written application should compare this value to the maximum size requested and be prepared to handle cases where they differ.
The TextField
shares the concept of input constraints with the {@link TextBox TextBox} class. The differentconstraints allow the application to request that the user's input be restricted in a variety of ways. The implementation is required to restrict the user's input as requested by the application. For example, if the application requests the NUMERIC
constraint on a TextField
, the implementation must allow only numeric characters to be entered.
The actual contents of the text object are set and modified by and are reported to the application through the TextBox
and TextField
APIs. The displayed contents may differ from the actual contents if the implementation has chosen to provide special formatting suitable for the text object's constraint setting. For example, a PHONENUMBER
field might be displayed with digit separators and punctuation as appropriate for the phone number conventions in use, grouping the digits into country code, area code, prefix, etc. Any spaces or punctuation provided are not considered part of the text object's actual contents. For example, a text object with the PHONENUMBER
constraint might display as follows:
|
but the actual contents of the object visible to the application through the APIs would be the string "4085551212
". The size
method reflects the number of characters in the actual contents, not the number of characters that are displayed, so for this example the size
method would return 10
.
Some constraints, such as DECIMAL
, require the implementation to perform syntactic validation of the contents of the text object. The syntax checking is performed on the actual contents of the text object, which may differ from the displayed contents as described above. Syntax checking is performed on the initial contents passed to the constructors, and it is also enforced for all method calls that affect the contents of the text object. The methods and constructors throw IllegalArgumentException
if they would result in the contents of the text object not conforming to the required syntax.
The value passed to the {@link #setConstraints setConstraints()} methodconsists of a restrictive constraint setting described above, as well as a variety of flag bits that modify the behavior of text entry and display. The value of the restrictive constraint setting is in the low order 16
bits of the value, and it may be extracted by combining the constraint value with the CONSTRAINT_MASK
constant using the bit-wise AND
(&
) operator. The restrictive constraint settings are as follows:
ANY
EMAILADDR
NUMERIC
PHONENUMBER
URL
DECIMAL
The modifier flags reside in the high order 16
bits of the constraint value, that is, those in the complement of the CONSTRAINT_MASK
constant. The modifier flags may be tested individually by combining the constraint value with a modifier flag using the bit-wise AND
(&
) operator. The modifier flags are as follows:
PASSWORD
UNEDITABLE
SENSITIVE
NON_PREDICTIVE
INITIAL_CAPS_WORD
INITIAL_CAPS_SENTENCE
The TextField
shares the concept of input modes with the {@link TextBox TextBox} class. The application can request that theimplementation use a particular input mode when the user initiates editing of a TextField
or TextBox
. The input mode is a concept that exists within the user interface for text entry on a particular device. The application does not request an input mode directly, since the user interface for text entry is not standardized across devices. Instead, the application can request that the entry of certain characters be made convenient. It can do this by passing the name of a Unicode character subset to the {@link #setInitialInputMode setInitialInputMode()} method. Calling this methodrequests that the implementation set the mode of the text entry user interface so that it is convenient for the user to enter characters in this subset. The application can also request that the input mode have certain behavioral characteristics by setting modifier flags in the constraints value.
The requested input mode should be used whenever the user initiates the editing of a TextBox
or TextField
object. If the user had changed input modes in a previous editing session, the application's requested input mode should take precedence over the previous input mode set by the user. However, the input mode is not restrictive, and the user is allowed to change the input mode at any time during editing. If editing is already in progress, calls to the setInitialInputMode
method do not affect the current input mode, but instead take effect at the next time the user initiates editing of this text object.
The initial input mode is a hint to the implementation. If the implementation cannot provide an input mode that satisfies the application's request, it should use a default input mode.
The input mode that results from the application's request is not a restriction on the set of characters the user is allowed to enter. The user MUST be allowed to switch input modes to enter any character that is allowed within the current constraint setting. The constraint setting takes precedence over an input mode request, and the implementation may refuse to supply a particular input mode if it is inconsistent with the current constraint setting.
For example, if the current constraint is ANY
, the call
|
should set the initial input mode to allow entry of uppercase Latin characters. This does not restrict input to these characters, and the user will be able to enter other characters by switching the input mode to allow entry of numerals or lowercase Latin letters. However, if the current constraint is NUMERIC
, the implementation may ignore the request to set an initial input mode allowing MIDP_UPPERCASE_LATIN
characters because these characters are not allowed in a TextField
whose constraint is NUMERIC
. In this case, the implementation may instead use an input mode that allows entry of numerals, since such an input mode is most appropriate for entry of data under the NUMERIC
constraint.
A string is used to name the Unicode character subset passed as a parameter to the {@link #setInitialInputMode setInitialInputMode()} method.String comparison is case sensitive.
Unicode character blocks can be named by adding the prefix "UCB
_" to the the string names of fields representing Unicode character blocks as defined in the J2SE class java.lang.Character.UnicodeBlock
. Any Unicode character block may be named in this fashion. For convenience, the most common Unicode character blocks are listed below.
UCB_BASIC_LATIN
UCB_GREEK
UCB_CYRILLIC
UCB_ARMENIAN
UCB_HEBREW
UCB_ARABIC
UCB_DEVANAGARI
UCB_BENGALI
UCB_THAI
UCB_HIRAGANA
UCB_KATAKANA
UCB_HANGUL_SYLLABLES
"Input subsets" as defined by the J2SE class java.awt.im.InputSubset
may be named by adding the prefix "IS_
" to the string names of fields representing input subsets as defined in that class. Any defined input subset may be used. For convenience, the names of the currently defined input subsets are listed below.
IS_FULLWIDTH_DIGITS
IS_FULLWIDTH_LATIN
IS_HALFWIDTH_KATAKANA
IS_HANJA
IS_KANJI
IS_LATIN
IS_LATIN_DIGITS
IS_SIMPLIFIED_HANZI
IS_TRADITIONAL_HANZI
MIDP has also defined the following character subsets:
MIDP_UPPERCASE_LATIN
- the subset ofIS_LATIN
that corresponds to uppercase Latin letters
MIDP_LOWERCASE_LATIN
- the subset ofIS_LATIN
that corresponds to lowercase Latin letters
Finally, implementation-specific character subsets may be named with strings that have a prefix of "X_
". In order to avoid namespace conflicts, it is recommended that implementation-specific names include the name of the defining company or organization after the initial "X_
" prefix.
For example, a Japanese language application might have a particular TextField
that the application intends to be used primarily for input of words that are "loaned" from languages other than Japanese. The application might request an input mode facilitating Hiragana input by issuing the following method call:
|
Implementations need not compile in all the strings listed above. Instead, they need only to compile in the strings that name Unicode character subsets that they support. If the subset name passed by the application does not match a known subset name, the request should simply be ignored without error, and a default input mode should be used. This lets implementations support this feature reasonably inexpensively. However, it has the consequence that the application cannot tell whether its request has been accepted, nor whether the Unicode character subset it has requested is actually a valid subset. @since MIDP 1.0
TextField
is the basic type for configurable text analysis. Analyzers for field types using this implementation should be defined in the schema.
@version $Id: TextField.java 1128859 2011-05-29 10:39:43Z mikemccand $
<s:textfield key="user" />
<s:textfield name="user" label="User Name" />
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|