Results 1 to 2 of 2

Thread: getLine from jTextArea

  1. #1

    Thread Starter
    Hyperactive Member xxarmoxx's Avatar
    Join Date
    Mar 2007
    Posts
    378

    getLine from jTextArea

    How can I get a single line from a jTextArea control?
    Last edited by xxarmoxx; Jul 7th, 2007 at 05:07 PM. Reason: I answered the original question

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: getLine from jTextArea

    Code:
        public String getLineText(int lineNumber)
        {
            try
            {
                int startIndex = jTextArea1.getLineStartOffset(lineNumber);
                int endIndex = jTextArea1.getLineEndOffset(lineNumber);
                java.lang.String line = jTextArea1.getText().substring(startIndex, endIndex - startIndex);
                return line;
            }
            catch (BadLocationException ex)
            {
                return "";
            }
        }
    Note that the "BadLocationException" is thrown if the line number specified didn't exist
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width