JTextArea/text component question

Discussion in 'Java' started by :-o, May 4, 2005.

  1. :-o

    :-o Guest

    Thanks,

    I'm using a JTextArea to store data read from a file and I need to implement a
    search->find
    feature that highlights the text found in the JTextArea.

    I've looked at Document and EditorKit.......found a highlighter that JTextArea
    inherits from javax.swing.text.

    Where should I look to find the methods required to do the setStartOffsetAt and
    setStopOffsetAt within
    text in the JTextArea?

    Or should I look at one of the other text components....
    :-o, May 4, 2005
    #1
    1. Advertising

  2. :-o

    Alan Moore Guest

    On Wed, 4 May 2005 15:24:24 -0400, ":-o" <> wrote:

    >Thanks,
    >
    >I'm using a JTextArea to store data read from a file and I need to implement a
    >search->find
    >feature that highlights the text found in the JTextArea.
    >
    >I've looked at Document and EditorKit.......found a highlighter that JTextArea
    >inherits from javax.swing.text.
    >
    >Where should I look to find the methods required to do the setStartOffsetAt and
    >setStopOffsetAt within
    >text in the JTextArea?
    >
    >Or should I look at one of the other text components....


    Will you be highlighting one result at a time, or all of them at once?
    If it's one at a time, you can use the existing Highlighter with
    textArea.getHighlighter(); otherwise you'll have to create a new one.
    In either case, you'll need to create a new HighlightPainter in a
    different color. DefaultHighter and its inner class
    DefaultHighlightPainter are what you'll be using. If you installed
    the JDK source code, you can look at the DefaultCaret class for an
    example of highlighting one hit at a time; that's where selection
    highlighting is done.
    Alan Moore, May 4, 2005
    #2
    1. Advertising

  3. :-o

    :-o Guest

    "Alan Moore" <> wrote in message
    news:...
    > On Wed, 4 May 2005 15:24:24 -0400, ":-o" <> wrote:
    >
    > >Thanks,
    > >
    > >I'm using a JTextArea to store data read from a file and I need to implement

    a
    > >search->find
    > >feature that highlights the text found in the JTextArea.
    > >
    > >I've looked at Document and EditorKit.......found a highlighter that

    JTextArea
    > >inherits from javax.swing.text.
    > >
    > >Where should I look to find the methods required to do the setStartOffsetAt

    and
    > >setStopOffsetAt within
    > >text in the JTextArea?
    > >
    > >Or should I look at one of the other text components....

    >
    > Will you be highlighting one result at a time, or all of them at once?


    Yes, highlighting one at a time.

    > If it's one at a time, you can use the existing Highlighter with
    > textArea.getHighlighter(); otherwise you'll have to create a new one.
    > In either case, you'll need to create a new HighlightPainter in a
    > different color. DefaultHighter and its inner class
    > DefaultHighlightPainter are what you'll be using. If you installed
    > the JDK source code, you can look at the DefaultCaret class for an
    > example of highlighting one hit at a time; that's where selection
    > highlighting is done.


    Thanks....
    :-o, May 4, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. bad_knee
    Replies:
    0
    Views:
    504
    bad_knee
    Jul 13, 2003
  2. bad_knee
    Replies:
    2
    Views:
    544
    bad_knee
    Jul 14, 2003
  3. Thomas Weidenfeller

    Re: JTextArea text is double-spaced?

    Thomas Weidenfeller, Jul 16, 2003, in forum: Java
    Replies:
    2
    Views:
    443
    Thomas Weidenfeller
    Jul 17, 2003
  4. Aaron Boxer

    JTextArea: get last line of text

    Aaron Boxer, Sep 29, 2003, in forum: Java
    Replies:
    3
    Views:
    5,329
    Aaron Boxer
    Sep 30, 2003
  5. Phillip
    Replies:
    2
    Views:
    3,171
Loading...

Share This Page