JTextArea/text component question

O

:-o

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....
 
A

Alan Moore

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.
 
O

:-o

Alan Moore said:
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....
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,904
Latest member
HealthyVisionsCBDPrice

Latest Threads

Top