Class TextInput

  • All Implemented Interfaces:
    ConstrainedVisual, Visual

    public class TextInput
    extends Component
    A component that allows a user to enter a single line of unformatted text.
    • Constructor Detail

      • TextInput

        public TextInput()
    • Method Detail

      • setSkin

        protected void setSkin​(Skin skin)
        Description copied from class: Component
        Sets the skin, replacing any previous skin.
        Overrides:
        setSkin in class Component
        Parameters:
        skin - The new skin.
      • getText

        public java.lang.String getText()
        Returns the text content of the text input.
        Returns:
        A string containing a copy of the text input's text content.
      • getText

        public java.lang.String getText​(int beginIndex,
                                        int endIndex)
        Returns a portion of the text content of the text input.
        Parameters:
        beginIndex - The starting index of the text to retrieve (inclusive).
        endIndex - The ending index of the text (exclusive).
        Returns:
        A string containing a copy of the text area's text content.
      • setText

        public void setText​(java.lang.String text)
      • setText

        public void setText​(java.lang.CharSequence text)
      • insertText

        public void insertText​(java.lang.CharSequence text,
                               int index)
      • removeText

        public void removeText​(int index,
                               int count)
      • getComposedText

        public AttributedStringCharacterIterator getComposedText()
        Return the current text that is in process of being composed using the Input Method Editor. This is temporary text that must be displayed, scrolled, etc. but is not a permanent part of what would be returned from getText() for instance.
        Returns:
        The current composed text or null if we're not using an IME or we're in English input mode, or user just committed or deleted the composed text.
      • setComposedText

        public void setComposedText​(AttributedStringCharacterIterator composedText)
        Called from the Input Method Editor callbacks to set the current composed text (that is, the text currently being composed into something meaningful).
        Parameters:
        composedText - The current composed text (which can be null for many different reasons).
      • getCharacters

        public java.lang.CharSequence getCharacters()
        Returns:
        A character sequence representing the text input's content.
      • getCharacters

        public java.lang.CharSequence getCharacters​(int start,
                                                    int end)
        Parameters:
        start - The start of the sequence (inclusive).
        end - The end of the sequence (exclusive).
        Returns:
        A (sub) character sequence representing the contents between the given indices.
      • getCharacterAt

        public char getCharacterAt​(int index)
        Parameters:
        index - Location of the character to retrieve.
        Returns:
        The character at a given index.
      • getCharacterCount

        public int getCharacterCount()
        Returns:
        The number of characters in the text input.
      • cut

        public void cut()
        Places any selected text on the clipboard and deletes it from the text input.
      • copy

        public void copy()
        Places any selected text on the clipboard.
      • paste

        public void paste()
        Inserts text from the clipboard into the text input.
      • undo

        public void undo()
      • getSelectionStart

        public final int getSelectionStart()
        Returns:
        The starting index of the selection.
      • getSelectionLength

        public final int getSelectionLength()
        Returns:
        The length of the selection; may be 0.
      • getSelection

        public final Span getSelection()
        Returns a span representing the current selection.
        Returns:
        A span containing the current selection. Both start and end points are inclusive. Returns null if the selection length is 0.
      • getCharSelection

        public final CharSpan getCharSelection()
        Returns a character span (start, length) representing the current selection.
        Returns:
        A char span with the start and length values.
      • setSelection

        public final void setSelection​(int selectionStart,
                                       int selectionLength)
        Sets the selection. The sum of the selection start and length must be less than the length of the text input's content.
        Parameters:
        selectionStart - The starting index of the selection.
        selectionLength - The length of the selection.
      • setSelection

        public final void setSelection​(Span selection)
        Sets the selection.
        Parameters:
        selection - The span (start inclusive to end inclusive).
        Throws:
        java.lang.IllegalArgumentException - if the selection span is null.
        See Also:
        setSelection(int, int)
      • setSelection

        public final void setSelection​(CharSpan selection)
        Sets the selection.
        Parameters:
        selection - The character span (start and length) for the selection.
        Throws:
        java.lang.IllegalArgumentException - if the character span is null.
        See Also:
        setSelection(int, int)
      • selectAll

        public final void selectAll()
        Selects all text.
      • clearSelection

        public final void clearSelection()
        Clears the selection.
      • getSelectedText

        public final java.lang.String getSelectedText()
        Returns the currently selected text.
        Returns:
        A new string containing a copy of the text in the selected range.
      • getTextSize

        public final int getTextSize()
        Returns the text size.
        Returns:
        The number of characters to display in the text input.
      • setTextSize

        public final void setTextSize​(int textSize)
        Sets the text size.
        Parameters:
        textSize - The number of characters to display in the text input.
        Throws:
        java.lang.IllegalArgumentException - if the size value is negative.
      • getMaximumLength

        public final int getMaximumLength()
        Returns the maximum length of the text input's text content.
        Returns:
        The maximum length of the text input's text content.
      • setMaximumLength

        public final void setMaximumLength​(int maximumLength)
        Sets the maximum length of the text input's text content.
        Parameters:
        maximumLength - The maximum length of the text input's text content.
        Throws:
        java.lang.IllegalArgumentException - if the length value is negative.
      • isPassword

        public final boolean isPassword()
        Returns the password flag.
        Returns:
        true if this is a password text input; false, otherwise.
      • setPassword

        public final void setPassword​(boolean password)
        Sets or clears the password flag. If the password flag is set, the text input will visually mask its contents.
        Parameters:
        password - true if this is a password text input; false, otherwise.
      • getPrompt

        public final java.lang.String getPrompt()
        Returns:
        The text input's prompt.
      • setPrompt

        public final void setPrompt​(java.lang.String prompt)
        Sets the text input's prompt.
        Parameters:
        prompt - The prompt text, or null for no prompt.
      • getTextKey

        public final java.lang.String getTextKey()
        Returns the text input's text key.
        Returns:
        The text key, or null if no text key is set.
      • setTextKey

        public final void setTextKey​(java.lang.String textKey)
        Sets the text input's text key.
        Parameters:
        textKey - The text key, or null to clear the binding.
      • getTextBindType

        public final BindType getTextBindType()
      • setTextBindType

        public final void setTextBindType​(BindType textBindType)
      • load

        public void load​(java.lang.Object context)
        Description copied from class: Component
        Copies bound values from the bind context to the component. This functionality must be provided by the subclass; the base implementation is a no-op.
        Overrides:
        load in class Component
        Parameters:
        context - The object to load the bound values from.
      • store

        public void store​(java.lang.Object context)
        Description copied from class: Component
        Copies bound values from the component to the bind context. This functionality must be provided by the subclass; the base implementation is a no-op.
        Overrides:
        store in class Component
        Parameters:
        context - The object to store the bound values into.
      • clear

        public void clear()
        Description copied from class: Component
        Clears any bound values in the component. This functionality must be provided by the subclass; the base implementation is a no-op.
        Overrides:
        clear in class Component
      • getInsertionPoint

        public final int getInsertionPoint​(int x)
      • getCharacterBounds

        public final Bounds getCharacterBounds​(int index)
      • getValidator

        public final Validator getValidator()
        Returns:
        The validator associated with this text input.
      • setValidator

        public final void setValidator​(Validator validator)
        Sets the validator associated with this text input.
        Parameters:
        validator - The validator to use, or null to use no validator.
      • isStrictValidation

        public final boolean isStrictValidation()
        Returns:
        The text input's strict validation flag.
      • setStrictValidation

        public final void setStrictValidation​(boolean strictValidation)
        Sets the text input's strict validation flag. When enabled, only valid text will be accepted by the text input.
        Parameters:
        strictValidation - The new flag setting.
      • isTextValid

        public final boolean isTextValid()
        Reports whether this text input's text is currently valid as defined by its validator.
        Returns:
        true if the text is valid or no validator is installed; false, otherwise.
      • isEditable

        public final boolean isEditable()
        Returns:
        The text area's editable flag.
      • setEditable

        public final void setEditable​(boolean editable)
        Sets the text area's editable flag.
        Parameters:
        editable - The new flag setting.