Results 1 to 7 of 7
  1. #1
    ramvaidhya is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default How to Highlight a String in JTextArea

    Hi All,
    My requirements is need to search a given text in JTextArea and need to highlight. Any early help is highly appreciated.

    Regards,
    Ram.:)

  2. #2
    ramvaidhya is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default

    Hello, I need to highlight string in JTextArea

  3. #3
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    7

    Default

    Use getText() to retrieve the text for search.

    Use select(start, end) to select the text you found.

  4. #4
    Gudradain is offline Member
    Join Date
    Nov 2008
    Posts
    44
    Rep Power
    0

    Default

    I'm not sure but I think you can't do it in a jTextArea.

    jTextArea only support 1 style for all the Document. So you can highlight all your text or nothing of it. Maybe I'm wrong

    You should use a jTextPane to do it instead.

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    I'm with Gudradain: use a JTextPane, not a JTextArea.

  6. #6
    ramvaidhya is offline Member
    Join Date
    Dec 2008
    Posts
    3
    Rep Power
    0

    Default i will try with JTextPane.

    Thanks for your reply, I will try with JTextPane.

  7. #7
    Gudradain is offline Member
    Join Date
    Nov 2008
    Posts
    44
    Rep Power
    0

    Default

    Hope you know how jTextPane works :).

    I have solution but I will let you try.

Similar Threads

  1. How to select/highlight an entire row in JTextPane
    By Maladict in forum AWT / Swing
    Replies: 6
    Last Post: 08-15-2008, 10:21 AM
  2. How to highlight text by drag and selection
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-25-2008, 11:35 AM
  3. delete string in JtextArea
    By cloudet in forum AWT / Swing
    Replies: 3
    Last Post: 05-05-2008, 11:06 AM
  4. GNU Source-highlight 2.7
    By levent in forum Java Software
    Replies: 0
    Last Post: 06-12-2007, 09:39 AM
  5. How to select/highlight an entire row in JTextArea
    By Valeriano in forum AWT / Swing
    Replies: 2
    Last Post: 05-28-2007, 12:20 PM

Posting Permissions

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