Class TextPane

    • Constructor Detail

      • TextPane

        public TextPane()
    • 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.
      • getDocument

        public Document getDocument()
        Returns:
        The document that backs the text pane.
      • setDocument

        public void setDocument​(Document document)
        Sets the document that backs the text pane. Documents are not shareable across multiple TextPanes; because a Document may contain Components, and a Component may only be in one Container at a time.
        Parameters:
        document - The new document to be displayed by this text pane.
      • setSaveHistory

        public void setSaveHistory​(boolean save)
        Some document rearrangements might not be suitable for undoing, so allow users to specify when to do so.
        Parameters:
        save - Whether or not to save history at this time.
      • insert

        public void insert​(char character)
      • insert

        public void insert​(java.lang.String text)
      • insertText

        public void insertText​(java.lang.String text,
                               int index)
      • insertImage

        public void insertImage​(Image image)
      • insertComponent

        public void insertComponent​(Component component)
      • insertParagraph

        public void insertParagraph()
      • getCharacterCount

        public int getCharacterCount()
        Returns character count of the document.
        Returns:
        The document's character count, or 0 if the document is null.
      • delete

        public void delete​(boolean backspace)
        Delete the currently selected text (if selectionLength > 0), or the character before or after the current cursor position, depending on the backspace flag.
        Parameters:
        backspace - true if the single character delete is the character before the current position, or false for the character after (at) the current position.
      • removeText

        public void removeText​(int offset,
                               int characterCount)
        Remove the text from the document starting at the given position for the given number of characters.
        Parameters:
        offset - Starting location to remove text.
        characterCount - The number of characters to remove.
      • cut

        public void cut()
      • copy

        public void copy()
      • paste

        public void paste()
      • undo

        public void undo()
      • redo

        public void redo()
      • getText

        public java.lang.String getText()
        Convenience method to get all the text from the current document into a single string.
        Returns:
        The complete text of the document as a string.
        See Also:
        setText(java.lang.String)
      • getText

        public java.lang.String getText​(int beginIndex,
                                        int endIndex)
        Convenience method to get a portion of the document text into a single string.
        Parameters:
        beginIndex - The 0-based offset where to start retrieving text.
        endIndex - The ending offset + 1 of the text to retrieve.
        Returns:
        The specified portion of the document text if there is any, or null if there is no document.
      • setText

        public void setText​(java.lang.String text)
        Convenience method to create a text-only document consisting of one paragraph per line of the given text.
        Parameters:
        text - The new complete text for the document.
      • setText

        public void setText​(java.net.URL textURL)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • setText

        public void setText​(java.io.File f)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • setText

        public void setText​(java.io.File f,
                            java.nio.charset.Charset cs)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • setText

        public void setText​(java.io.Reader textReader)
                     throws java.io.IOException
        Throws:
        java.io.IOException
      • 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).
      • getSelectionStart

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

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

        public 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 is empty.
      • getCharSelection

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

        public 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 new span describing the selection.
        Throws:
        java.lang.IllegalArgumentException - if the 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 void selectAll()
        Selects all text.
      • clearSelection

        public void clearSelection()
        Clears the selection.
      • getSelectedText

        public java.lang.String getSelectedText()
        Returns the currently selected text.
        Returns:
        A new string containing a copy of the text in the selected range, or null if nothing is selected.
      • isEditable

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

        public void setEditable​(boolean editable)
        Sets the text pane's editable flag.
        Parameters:
        editable - Whether or not the text should be editable now.
      • getExpandTabs

        public boolean getExpandTabs()
      • setExpandTabs

        public void setExpandTabs​(boolean expandTabs)
        Sets whether tab characters (\t) are expanded to an appropriate number of spaces during setText(java.lang.String) and paste() operations. Note: doing this for keyboard input is handled in the skin.
        Parameters:
        expandTabs - true to replace tab characters with space characters (depending on the setting of the TextPane.Skin.getTabWidth() value) or false to leave tabs alone. Note: this only affects tabs encountered during program operations; tabs entered via the keyboard by the user are always expanded, regardless of this setting.
      • getInsertionPoint

        public int getInsertionPoint​(int x,
                                     int y)
      • getRowAt

        public int getRowAt​(int offset)
      • getRowCount

        public int getRowCount()
      • getCharacterBounds

        public Bounds getCharacterBounds​(int offset)
      • dumpNode

        public static void dumpNode​(java.lang.String msg,
                                    Node node,
                                    int indent)