Class TextField

  • All Implemented Interfaces:
    Styleable, EventTarget, Skinnable
    Direct Known Subclasses:
    AutoCompleteTextField

    public class TextField
    extends TextInput
    A Text input component that allows a user to enter a single line of unformatted text.

    User may choose to add additional information on the text input control by using :

    • Prompt Text - A place holder text inside a TextInput which is erased when focus is received by it.
    • Float Text- A place holder text inside a TextInput which is transitioned to the top of the TextInput when focus is received by it.

    Please note that float text has a higher precedence over prompt text i.e. if both the values are set, the latter will be removed.

    Error validators are used to validate the input based on a user provided function.

    The following picture shows the Textfield with a float text applied. It shows an image before and after the user starts writing in the Textfield.

    Screenshot of TextField at rest

    Screenshot of TextField while typing

    Since:
    2.2.0
    See Also:
    TextInput
    • Property Detail

      • maxLength

        public final IntegerProperty maxLengthProperty
        The number of characters for overflow. This property can be used to put a character restriction in place by changing the style of the TextField when it has exceeded the maxLength limit.

        Default value is 0.

        Style Guide:

        When the text exceeds the max length, a PseudoClass "error" is added to the TextField. For styling the counter label, which is added as a direct child of the TextField, you can use the style-class "counter".
        See Also:
        getMaxLength(), setMaxLength(int)
    • Constructor Detail

      • 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 Detail

      • setMaxLength

        public final void setMaxLength​(int maxLength)
        Sets the value of the property maxLength.
        Property description:
        The number of characters for overflow. This property can be used to put a character restriction in place by changing the style of the TextField when it has exceeded the maxLength limit.

        Default value is 0.

        Style Guide:

        When the text exceeds the max length, a PseudoClass "error" is added to the TextField. For styling the counter label, which is added as a direct child of the TextField, you can use the style-class "counter".
      • getMaxLength

        public final int getMaxLength()
        Gets the value of the property maxLength.
        Property description:
        The number of characters for overflow. This property can be used to put a character restriction in place by changing the style of the TextField when it has exceeded the maxLength limit.

        Default value is 0.

        Style Guide:

        When the text exceeds the max length, a PseudoClass "error" is added to the TextField. For styling the counter label, which is added as a direct child of the TextField, you can use the style-class "counter".
      • maxLengthProperty

        public final IntegerProperty maxLengthProperty()
        The number of characters for overflow. This property can be used to put a character restriction in place by changing the style of the TextField when it has exceeded the maxLength limit.

        Default value is 0.

        Style Guide:

        When the text exceeds the max length, a PseudoClass "error" is added to the TextField. For styling the counter label, which is added as a direct child of the TextField, you can use the style-class "counter".
        See Also:
        getMaxLength(), setMaxLength(int)