APIdia Launch Partner
Top Description Inners Fields Constructors Methods
javafx.scene.control

public Class TextField

extends TextInputControl
Class Inheritance
Known Direct Subclasses
com.sun.javafx.scene.control.FakeFocusTextField, com.sun.javafx.scene.control.skin.InputFieldSkin.InnerTextField, javafx.scene.control.PasswordField
Imports
java.util.ArrayList, .Collections, .List, javafx.beans.property.IntegerProperty, .ObjectProperty, .ObjectPropertyBase, javafx.beans.value.WritableValue, javafx.css.CssMetaData, .StyleableIntegerProperty, .StyleableObjectProperty, .StyleableProperty, .Styleable, javafx.event.ActionEvent, .EventHandler, javafx.geometry.Pos, javafx.scene.AccessibleRole, javafx.css.converter.EnumConverter, .SizeConverter, javafx.scene.control.skin.TextFieldSkin

Text input component that allows a user to enter a single line of unformatted text. Unlike in previous releases of JavaFX, support for multi-line input is not available as part of the TextField control, however this is the sole-purpose of the TextArea control. Additionally, if you want a form of rich-text editing, there is also the HTMLEditor control.

TextField supports the notion of showing prompt text to the user when there is no text already in the TextField (either via the user, or set programmatically). This is a useful way of informing the user as to what is expected in the text field, without having to resort to tooltips or on-screen labels.

Example:

 var textField = new TextField("Hello World!");
Image of the TextField control
Since
JavaFX 2.0
See Also
TextArea

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class
private static class

Field Summary

Modifier and TypeField and Description
private ObjectProperty<Pos>
public static final int
private ObjectProperty<EventHandler<ActionEvent>>
onAction

The action handler associated with this text field, or null if no action handler is assigned.

private IntegerProperty
prefColumnCount

The preferred number of text columns.

Constructor Summary

AccessConstructor and Description
public
TextField()

Creates a TextField with empty text content.

public
TextField(String
A string for text content.
text
)

Creates a TextField with initial text content.

Method Summary

Modifier and TypeMethod and Description
public final ObjectProperty<Pos>

Returns:

the alignment property
alignmentProperty
()

Specifies how the text should be aligned when there is empty space within the TextField.

protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control.

pack-priv String
public final Pos
public CharSequence

Returns:

the character sequence backing the text field's content
getCharacters
()

Returns the character sequence backing the text field's content.

public static List<CssMetaData<? extends Styleable, ?>>

Returns:

the CssMetaData
getClassCssMetaData
()

Hides javafx.scene.control.TextInputControl.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

public List<CssMetaData<? extends Styleable, ?>>
getControlCssMetaData()

Overrides javafx.scene.control.TextInputControl.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

public final EventHandler<ActionEvent>
public final int
public final ObjectProperty<EventHandler<ActionEvent>>
public final IntegerProperty
public final void
public final void
public final void
setPrefColumnCount(int value)

Inherited from javafx.scene.control.TextInputControl:
anchorPropertyappendTextbackwardcancelEditcaretPositionPropertyclearcommitValuecontainsInvalidCharacterscopycutdeleteNextChardeletePreviousChardeleteTextdeleteTextdeselecteditablePropertyendendOfNextWordexecuteAccessibleActionextendSelectionfilterInputfontPropertyforwardgetAnchorgetCaretPositiongetContentgetFontgetLengthgetPromptTextgetSelectedTextgetSelectiongetTextgetTextgetTextFormatterhomeinsertTextisEditableisRedoableisUndoablelengthPropertynextWordpastepositionCaretpreviousWordpromptTextPropertyqueryAccessibleAttributeredoredoablePropertyreplaceSelectionreplaceTextreplaceTextselectAllselectBackwardselectedTextPropertyselectEndselectEndOfNextWordselectForwardselectHomeselectionPropertyselectNextWordselectPositionCaretselectPreviousWordselectRangesetEditablesetFontsetPromptTextsetTextsetTextFormattertextFormatterPropertytextPropertytextUpdatedundoundoableProperty

Field Detail

alignmentback to summary
private ObjectProperty<Pos> alignment
DEFAULT_PREF_COLUMN_COUNTback to summary
public static final int DEFAULT_PREF_COLUMN_COUNT

The default value for prefColumnCount.

onActionback to summary
private ObjectProperty<EventHandler<ActionEvent>> onAction

The action handler associated with this text field, or null if no action handler is assigned. The action handler is normally called when the user types the ENTER key.

prefColumnCountback to summary
private IntegerProperty prefColumnCount

The preferred number of text columns. This is used for calculating the TextField's preferred width.

Constructor Detail

TextFieldback to summary
public TextField()

Creates a TextField with empty text content.

TextFieldback to summary
public TextField(String text)

Creates a TextField with initial text content.

Parameters
text:String

A string for text content.

Method Detail

alignmentPropertyback to summary
public final ObjectProperty<Pos> alignmentProperty()

Specifies how the text should be aligned when there is empty space within the TextField.

Returns:ObjectProperty<Pos>

the alignment property

Since
JavaFX 2.1
createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Doc from javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).

Annotations
@Override
filterInputback to summary
pack-priv String filterInput(String text)

Overrides javafx.scene.control.TextInputControl.filterInput.

Annotations
@Override
getAlignmentback to summary
public final Pos getAlignment()
getCharactersback to summary
public CharSequence getCharacters()

Returns the character sequence backing the text field's content.

Returns:CharSequence

the character sequence backing the text field's content

getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.control.TextInputControl.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

Returns:List<CssMetaData<? extends Styleable, ?>>

the CssMetaData

Since
JavaFX 8.0
getControlCssMetaDataback to summary
public List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData()

Overrides javafx.scene.control.TextInputControl.getControlCssMetaData.

Doc from javafx.scene.control.TextInputControl.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

Annotations
@Override
Since
JavaFX 8.0
getOnActionback to summary
public final EventHandler<ActionEvent> getOnAction()
getPrefColumnCountback to summary
public final int getPrefColumnCount()
onActionPropertyback to summary
public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty()
prefColumnCountPropertyback to summary
public final IntegerProperty prefColumnCountProperty()
setAlignmentback to summary
public final void setAlignment(Pos value)
setOnActionback to summary
public final void setOnAction(EventHandler<ActionEvent> value)
setPrefColumnCountback to summary
public final void setPrefColumnCount(int value)
javafx.scene.control back to summary

private Class TextField.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<TextField, Pos>
private static final CssMetaData<TextField, Number>
private static final List<CssMetaData<? extends Styleable, ?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ALIGNMENTback to summary
private static final CssMetaData<TextField, Pos> ALIGNMENT
PREF_COLUMN_COUNTback to summary
private static final CssMetaData<TextField, Number> PREF_COLUMN_COUNT
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()
javafx.scene.control back to summary

private final Class TextField.TextFieldContent

extends ContentBase
Class Inheritance

Field Summary

Modifier and TypeField and Description
private StringBuilder

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
delete(int start, int end, boolean notifyListeners)

Implements javafx.scene.control.TextInputControl.Content.delete.

Removes a sequence of characters from the content.

public String
get(int start, int end)

Implements javafx.scene.control.TextInputControl.Content.get.

Retrieves a subset of the content.

public String
get()

Implements javafx.beans.value.ObservableObjectValue.get.

Returns the current value of this ObservableObjectValue<T>.

public String
getValue()

Implements javafx.beans.value.ObservableValue.getValue.

Returns the current value of this ObservableValue

public void
insert(int index, String text, boolean notifyListeners)

Implements javafx.scene.control.TextInputControl.Content.insert.

Inserts a sequence of characters into the content.

public int
length()

Implements javafx.scene.control.TextInputControl.Content.length.

Returns the number of characters represented by the content.

Inherited from javafx.scene.control.TextInputControl.ContentBase:
addListeneraddListenerfireValueChangedEventremoveListenerremoveListener

Field Detail

charactersback to summary
private StringBuilder characters

Constructor Detail

TextFieldContentback to summary
private TextFieldContent()

Method Detail

deleteback to summary
public void delete(int start, int end, boolean notifyListeners)

Implements javafx.scene.control.TextInputControl.Content.delete.

Doc from javafx.scene.control.TextInputControl.Content.delete.

Removes a sequence of characters from the content.

Annotations
@Override
getback to summary
public String get(int start, int end)

Implements javafx.scene.control.TextInputControl.Content.get.

Doc from javafx.scene.control.TextInputControl.Content.get.

Retrieves a subset of the content.

Annotations
@Override
getback to summary
public String get()

Implements javafx.beans.value.ObservableObjectValue.get.

Doc from javafx.beans.value.ObservableObjectValue.get.

Returns the current value of this ObservableObjectValue<T>.

Annotations
@Override
getValueback to summary
public String getValue()

Implements javafx.beans.value.ObservableValue.getValue.

Doc from javafx.beans.value.ObservableValue.getValue.

Returns the current value of this ObservableValue

Annotations
@Override
insertback to summary
public void insert(int index, String text, boolean notifyListeners)

Implements javafx.scene.control.TextInputControl.Content.insert.

Doc from javafx.scene.control.TextInputControl.Content.insert.

Inserts a sequence of characters into the content.

Annotations
@Override
lengthback to summary
public int length()

Implements javafx.scene.control.TextInputControl.Content.length.

Doc from javafx.scene.control.TextInputControl.Content.length.

Returns the number of characters represented by the content.

Annotations
@Override