Class TextField

All Implemented Interfaces:
Styleable, EventTarget, Skinnable
Direct Known Subclasses:
PasswordField

public class TextField extends TextInputControl
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:
  • Property Details

  • Field Details

  • Constructor Details

    • TextField

      public TextField()
      Creates a TextField with empty text content.
    • TextField

      public TextField(String text)
      Creates a TextField with initial text content.
      Parameters:
      text - A string for text content.
  • Method Details

    • getCharacters

      public CharSequence getCharacters()
      Returns the character sequence backing the text field's content.
      Returns:
      the character sequence backing the text field's content
    • prefColumnCountProperty

      public final IntegerProperty prefColumnCountProperty()
      The preferred number of text columns. This is used for calculating the TextField's preferred width.
      See Also:
    • getPrefColumnCount

      public final int getPrefColumnCount()
      Gets the value of the property prefColumnCount.
      Property description:
      The preferred number of text columns. This is used for calculating the TextField's preferred width.
    • setPrefColumnCount

      public final void setPrefColumnCount(int value)
      Sets the value of the property prefColumnCount.
      Property description:
      The preferred number of text columns. This is used for calculating the TextField's preferred width.
    • onActionProperty

      public final ObjectProperty<EventHandler<ActionEvent>> onActionProperty()
      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.
      See Also:
    • getOnAction

      public final EventHandler<ActionEvent> getOnAction()
      Gets the value of the property onAction.
      Property description:
      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.
    • setOnAction

      public final void setOnAction(EventHandler<ActionEvent> value)
      Sets the value of the property onAction.
      Property description:
      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.
    • alignmentProperty

      public final ObjectProperty<Pos> alignmentProperty()
      Specifies how the text should be aligned when there is empty space within the TextField.
      Since:
      JavaFX 2.1
      See Also:
    • setAlignment

      public final void setAlignment(Pos value)
      Sets the value of the property alignment.
      Property description:
      Specifies how the text should be aligned when there is empty space within the TextField.
      Since:
      JavaFX 2.1
    • getAlignment

      public final Pos getAlignment()
      Gets the value of the property alignment.
      Property description:
      Specifies how the text should be aligned when there is empty space within the TextField.
      Since:
      JavaFX 2.1
    • getClassCssMetaData

      public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
      Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.
      Returns:
      the CssMetaData
      Since:
      JavaFX 8.0
    • getControlCssMetaData

      public List<CssMetaData<? extends Styleable,?>> getControlCssMetaData()
      Gets the unmodifiable list of the control's CSS-styleable properties.
      Overrides:
      getControlCssMetaData in class TextInputControl
      Returns:
      the unmodifiable list of the control's CSS-styleable properties
      Since:
      JavaFX 8.0